Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ==============================================================================
- ; Raw flash commands tester.
- ; ===== Equates ================================================================
- .nolist
- #include "ti83plus.txt"
- .list
- ;spaddr .equ appBackUpScreen
- inputerFlags .equ Asm_Flag1
- secondNibble .equ 0
- ;====== Header =================================================================
- .org $9D93
- .db t2ByteTok, tAsmCmp
- ;====== Init ===================================================================
- call UnlockFlash
- ;ld (spaddr), sp
- pop hl
- push hl
- ld (spaddr), hl
- ld hl, mSplash
- jp menu
- ;====== Flash commands =========================================================
- ;------ Flash read -------------------------------------------------------------
- readFlashByte:
- B_CALL(_ClrScrn)
- B_CALL(_HomeUp)
- ld hl, readFlashByteMsg
- b_call(_PutS)
- call getHexByte
- out (6), a
- b_call(_NewLine)
- ld hl, readFlashByteAddrMsg
- b_call(_PutS)
- call getHexByte
- ld h, a
- call getHexByte
- ld l, a
- push hl
- b_call(_NewLine)
- ld hl, readFlashByteOutputMsg
- b_call(_PutS)
- pop hl
- ld l, (hl)
- ld de, OP1
- call LToHexString
- ld hl, OP1
- b_call(_PutS)
- jp waitAndReturn
- ;------ Flash write ------------------------------------------------------------
- writeFlashByte:
- B_CALL(_ClrScrn)
- B_CALL(_HomeUp)
- ld hl, writeFlashByteMsg
- b_call(_PutS)
- call getHexByte
- ;out (6), a
- push af
- b_call(_NewLine)
- ld hl, writeFlashByteAddrMsg
- b_call(_PutS)
- call getHexByte
- ld h, a
- call getHexByte
- ld l, a
- push hl
- b_call(_NewLine)
- ld hl, writeFlashBytePageMsg
- b_call(_PutS)
- call getHexByte
- push af
- b_call(_NewLine)
- ; 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
- di
- xor a
- out (6), a
- ; 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 af
- out (6), a
- 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
- ld hl, errTimeoutMsg
- b_call(_PutS)
- jp waitAndReturn
- programDone:
- ei
- ld hl, mMainMenu
- jp menu
- ;------ Erase sector -----------------------------------------------------------
- eraseSector:
- B_CALL(_ClrScrn)
- B_CALL(_HomeUp)
- ld hl, eraseSectorMsg
- b_call(_PutS)
- call getHexByte
- ;out (6), a
- push af
- b_call(_NewLine)
- ld hl, erasingSectorMsg
- b_call(_PutS)
- ld hl, 4000h
- ; 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
- di
- xor a
- out (6), a
- ; reset bus (not needed by 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, 080h
- ld (4AAAh), a
- ; Fourth bus cycle---unlock (again)
- ld a, 0AAh
- ld (4AAAh), a
- ; Fifth bus cycle---unlock (again)
- ld a, 55h
- ld (4555h), a
- ; Sixth bus cycle---select sector
- pop af
- out (6), a
- ld a, 30h
- ld (hl), a
- ; Wait for data to be good
- ; "During the Embedded Erase Algorithm, an attempt to read the device will
- ; produce a '0' at the DQ7 output. Upon completion of the Embedded Erase
- ; Algorithm an attempt to read the device will produce a '1' at the DQ7 output."
- ; "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
- eraseWaitLoop:
- ld a, 0FDh
- out (1), a
- in a, (1)
- cp 0BFh
- jr z, abortErase
- cp 0FDh
- jr nz, eraseWaitLoopCont
- ld a, 0B0h
- ld (4000h), a
- ld a, "+"
- b_call(_PutMap)
- ld a, 30h
- ld (4000h), a
- eraseWaitLoopCont:
- ld a, (4000h)
- bit 7, a
- jr nz, eraseDone
- bit 5, a
- jr z, eraseWaitLoop
- abortErase:
- ld a, 0F0h
- ld (4000h), a
- ld hl, errTimeoutMsg
- b_call(_PutS)
- jp waitAndReturn
- eraseDone:
- ei
- ld hl, mMainMenu
- jp menu
- ;====== Autoselect commands ====================================================
- ; "The system must write the reset command to exit the
- ; autoselect mode and return to reading array data."---AMD data sheet
- ; AMD also says you uses different autoselect codes for byte and word mode.
- ;------ Manufacture's Code -----------------------------------------------------
- getManufacturesCode:
- B_CALL(_ClrScrn)
- B_CALL(_HomeUp)
- ld hl, manCodeMsg
- b_call(_PutS)
- ; Autoselect sequence
- ; This code tries it TI's way.
- di
- ; First bus cycle---unlock
- ld a, 2
- out (6), a
- ld a, 0AAh
- ld (6AAAh), a
- ; Second bus cycle---unlock
- ld a, 1
- out (6), a
- ld a, 55h
- ld (5555h), a
- ; Third bus cycle---write command
- ld a, 2
- out (6), a
- ld a, 090h
- ld (6AAAh), a
- ; Read autoselect code
- ld a, 1
- out (6), a
- ld l, (5000h)
- ld a, 0F0h
- ld (4000h), a
- push hl
- pop hl
- ei
- ld de, OP1
- call LToHexString
- ld hl, OP1
- b_call(_PutS)
- jp waitAndReturn
- ;------ Device Code ------------------------------------------------------------
- getDeviceCode:
- B_CALL(_ClrScrn)
- B_CALL(_HomeUp)
- ld hl, deviceCodeMsg
- b_call(_PutS)
- ; Autoselect sequence
- ; This code tries it my way.
- di
- xor a
- out (6), 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, 090h
- ; ld (4AAAh), a
- ; Read autoselect code
- ld l, (4047h) ;4001h
- ld a, 0F0h
- ld (4000h), a
- push hl
- pop hl
- ei
- ld de, OP1
- call LToHexString
- ld hl, OP1
- b_call(_PutS)
- jp waitAndReturn
- ;------ Sector Protection ------------------------------------------------------
- getSectorProtection:
- B_CALL(_ClrScrn)
- B_CALL(_HomeUp)
- ld hl, sectorProtCodeMsg
- b_call(_PutS)
- call getHexByte
- push af
- ld hl, sectorProtOutputMsg
- b_call(_PutS)
- ; Autoselect sequence
- di
- xor a
- out (6), 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, 090h
- ld (4AAAh), a
- ; Read autoselect code
- pop af
- out (6), a
- ld l, (4004h) ;4002h
- ld a, 0F0h
- ld (4000h), a
- push hl
- pop hl
- ei
- ld de, OP1
- call LToHexString
- ld hl, OP1
- jp waitAndReturn
- ;====== ========================================================================
- waitAndReturn:
- ; im 1
- ; ei
- ; ld hl, 8000h
- ; ld de, 8000h
- ; ld bc, 8000h
- ; ldir ; waste clock cycles
- b_call(_GetKey)
- ld hl, mMainMenu
- jp menu
- ;====== Term ===================================================================
- quit:
- b_call(_NewLine)
- quitNoNewLine:
- B_CALL(_FlashWriteDisable)
- set indicRun, (iy+indicFlags)
- res DonePrgm, (iy+DoneFlags)
- res OnInterrupt, (iy+OnFlags)
- ;ld sp, (spaddr)
- im 1
- ei
- ld hl, (spaddr)
- jp (hl)
- ;ld hl, (spaddr)
- ;ret
- ;====== Routines ===============================================================
- ldHLindirect:
- ld a, (hl)
- inc hl
- ld h, (hl)
- ld l, a
- ret
- ;------ Menu -------------------------------------------------------------------
- menu:
- ; Simple menu routine.
- ; HL points to a data structure that describes the menu.
- ; The first item in the menu is a zero-termed string to be displayed.
- ; After that, there is a list of acceptable keys and jump addresses.
- ; This is a JUMP not a CALL!
- im 1
- ei
- push hl
- ;set appAutoScroll, (iy+appFlags)
- push hl
- B_CALL(_ClrScrn)
- ld hl, 0
- ld (curRow), hl
- pop hl
- b_call(_PutS)
- push hl
- menuKeyLoop:
- b_call(_GetKey);_GetCSC)
- pop hl
- push hl
- ld b, a
- ld a, (hl) ; sanity check
- or a ;
- jp z, quit
- mkla: ld a, (hl)
- or a
- jr z, menuKeyLoop
- cp b
- jr z, mklb
- inc hl
- inc hl
- inc hl
- jr mkla
- mklb: pop de
- inc hl
- call ldHLindirect
- push af
- ld a, (hl)
- or a
- jr z, mklc
- pop af
- jp (hl)
- mklc: pop af
- inc hl
- jp menu
- ;------ ------------------------------------------------------------------------
- ; These routines are by Milos "baze" Bazelides, from the web page
- ; http://baze.au.com/misc/z80bits.html
- HLToHexString:
- ;Input: HL = number to convert, DE = location of ASCII string
- ;Output: ASCII string at (DE)
- ld a,h
- call LNum1
- ld a,h
- call LNum2
- LToHexString: ld a,l
- call LNum1
- ld a,l
- jr LNum2
- LNum1: rra
- rra
- rra
- rra
- LNum2: or 0F0h
- daa
- add a,0A0h
- adc a,40h
- ld (de),a
- inc de
- xor a
- ld (de), a
- ret
- ;------ Hex input --------------------------------------------------------------
- getHexByte:
- ; Do not attempt to get a byte across a line break.
- ; Gets byte at current location. Returns byte in A
- ; Registers:
- ; b: returns nibble from getNibble
- ; d: byte
- push bc
- push de
- push hl
- B_CALL(_CursorOn)
- getHexByteFirstNibble:
- res secondNibble, (iy+inputerFlags)
- call getNibble
- sla b
- sla b
- sla b
- sla b
- push bc ; ld d, b
- set secondNibble, (iy+inputerFlags)
- call getNibble
- ld a, b
- pop bc
- add a, b ;add a, d
- push af
- B_CALL(_CursorOff)
- pop af
- pop hl
- pop de
- pop bc
- ret
- getNibble:
- ; Gets a single nibble. Set secondNibble in IY+inputerFlags to allow backspace.
- ; Returns nibble in B.
- B_CALL(_GetCSC)
- ld b, 0
- cp sk0
- jr z, nibble0
- cp sk1
- jr z, nibble1
- cp sk2
- jr z, nibble2
- cp sk3
- jr z, nibble3
- cp sk4
- jr z, nibble4
- cp sk5
- jr z, nibble5
- cp sk6
- jr z, nibble6
- cp sk7
- jr z, nibble7
- cp sk8
- jr z, nibble8
- cp sk9
- jr z, nibble9
- cp skMath
- jr z, nibbleA
- cp skMatrix
- jr z, nibbleB
- cp skPrgm
- jr z, nibbleC
- cp skRecip
- jr z, nibbleD
- cp skSin
- jr z, nibbleE
- cp skCos
- jr z, nibbleF
- cp skDel
- jr z, getNibbleBackspace
- cp skLeft
- jr z, getNibbleBackspace
- ; cp skClear
- ; jp z, quit
- ; cp skMode
- ; jp z, quit
- jr getNibble
- nibbleF: inc b
- nibbleE: inc b
- nibbleD: inc b
- nibbleC: inc b
- nibbleB: inc b
- nibbleA: inc b
- nibble9: inc b
- nibble8: inc b
- nibble7: inc b
- nibble6: inc b
- nibble5: inc b
- nibble4: inc b
- nibble3: inc b
- nibble2: inc b
- nibble1: inc b
- nibble0:
- ld a, b
- ld c, '0'
- ld a, 9
- cp b
- jr nc, number
- ld c, 'A'-0Ah
- number:
- ld a, b
- add a, c
- B_CALL(_PutC)
- ret
- getNibbleBackspace:
- bit secondNibble, (iy+inputerFlags)
- jr z, getNibble
- ld a, (curCol)
- dec a
- ld (curCol), a
- ld a, ' '
- B_CALL(_PutMap)
- pop bc ; stack
- jp getHexByteFirstNibble
- ;------ ------------------------------------------------------------------------
- #include "unlockflash.asm"
- ;====== Data ===================================================================
- ; 1234567890123456
- mSplash:
- .db "Raw Flash Tools "
- .db "26 Auguest 2009 "
- .db "Flash is unlockd"
- .db "Press enter. . ."
- .db 0
- .db kEnter
- .dw mMainMenu-1
- .db 0
- mMainMenu:
- .db "Raw Flash Tools:"
- .db "1. Read "
- .db "2. Program "
- .db "3. Sector erase "
- .db "4. Autoselect "
- .db "5. Quit"
- .db 0
- .db k1
- .dw readFlashByte
- .db k2
- .dw writeFlashByte
- .db k3
- .dw eraseSector
- .db k4
- .dw mAutoselect-1
- .db k5
- .dw quit
- .db 0
- mAutoselect:
- .db "Autoselect: "
- .db "1. Manufact.Code"
- .db "2. Device Code "
- .db "3. Sector prot. "
- .db "4. Return"
- .db 0
- .db k1
- .dw getManufacturesCode
- .db k2
- .dw getDeviceCode
- .db k3
- .dw getSectorProtection
- .db k4
- .dw mMainMenu-1
- .db 0
- readFlashByteMsg:
- ; 1234567890123456
- .db "Read flash byte:"
- .db "Enter page: "
- .db 0
- writeFlashByteAddrMsg:
- readFlashByteAddrMsg:
- .db "Enter addr: ", 0
- readFlashByteOutputMsg:
- .db "Result: ", 0
- writeFlashByteMsg:
- .db "Write flash byte"
- .db "Enter data: "
- .db 0
- writeFlashBytePageMsg:
- .db "Enter page: ", 0
- eraseSectorMsg:
- .db "Erase sector: "
- .db "Enter SA:"
- .db 0
- erasingSectorMsg:
- .db "Erasing sector! "
- .db "Press ENTER to "
- .db "test erase "
- .db "suspend, or "
- .db "CLEAR to abort."
- .db 0
- manCodeMsg:
- .db "Manufacture's "
- .db "code: "
- .db 0
- deviceCodeMsg:
- .db "Device code: ", 0
- sectorProtCodeMsg:
- .db "Sector Prot Test"
- .db "Enter sector: "
- .db 0
- sectorProtOutputMsg:
- .db "Result: ", 0
- errTimeoutMsg:
- ; 1234567890123456
- .db "The operation "
- .db "has failed."
- .db 0
- ;panicText:
- ; .db "Panic:", 0
- spaddr:
- .dw 0
- .end
- .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement