; FLASH GORDON driver ; Copyright 2012, Adrien Destugues ; This program is distributed under the terms of the MIT licence ; Start here. DI LD HL, 0xC9FB LD (0x38), HL ; Move the screen to $8000 or $0000 so we can display things to the user, while ; C000 will write to the ROM and 4000 will hold the data to write... That could ; get a bit messy so maybe we will need to use the screen at 4000 as a buffer ; for the ROM data as well. Or just use a bank for that ? ; TODO ; Map the ROM in LD BC, 0x7F85 OUT (C),C ; ask the user to enable writing ; TODO ; Turns out with the MegaFlash design, we can't both read and write. When the ; memory is in write mode, reading is disabled. This means we can't identify ; the chip, or use the data polling features. And we have to go for the ; worst-case timing given in the datasheet :( ; ... anyway, start with erasing the sectors we need. LD B, 4 ERASE PUSH BC LD A, 0x80 ; ERASE CALL send_command CALL prepare_command LD B,0xDF LD C,5 ; ROM number to write (FIXME get it as a RSX param) OUT (C),C ; Compute address near start of sector POP BC LD A,B DEC A SLA A SLA A ADD 0xC0 LD H,A LD E, 0x30 LD (HL), E ; This will delay long enough - we need at least 25ms EI HALT HALT HALT HALT DI DJNZ ERASE ; Ok, now that we erased the 4 sectors we needed, we can write data to them LD HL, 0xC000 LD IX, 0x4000 PROGRAM LD A, 0xA0 ; BYTE PROGRAM ; 2 10 PUSH HL ; 3 13 CALL send_command ; 5 18 LD B,0xDF LD C,5 ; ROM number to write (FIXME get it as a RSX param) OUT (C),C POP HL LD A,(IX + 0) LD (HL),A ; Write occurs here. Need to wait 20 NOPs before next ; operation on ROM. Our code is slow enough already ! INC IX ; 3 5 INC HL ; 2 2 LD A,H OR L JR NZ, PROGRAM ; 3 8 JR $ ; Now reuse and adapt the code from OUL guys ! ; TODO ; That's all folks ! RET ; Helper routines ----------------------------------------------------- ; Send a command to the ROM. The available commands are : ;ERASE equ 0x80 IDENTIFY equ 0x90 BYTEPROG equ 0xA0 RESET equ 0xF0 ; Input: Commend to send in A register send_command: ; That code is shared with sector erase which has some tricks call prepare_command ; Select ROM 1 again and write the command to address 0xEAAA INC C OUT (C),C EX DE,HL LD (HL), A ; Select ROM 0xFF, which basically prevents future accesses to get to the ; Flash chip. DEC C DEC C OUT (C),C RET prepare_command: ; Select ROM 1 LD BC,0xDF01 LD HL,0xD555 LD DE,0xEAAA ; Select ROM 1 and write 0xAA to address 0xD555 OUT (C),C LD (HL),E ; Select ROM 2 and write 0x55 to address 0xEAAA DEC C OUT (C),C EX DE,HL LD (HL), E RET ; Print value of A, as 2 hex digits printhex PUSH AF RRA RRA RRA RRA ;divise A par 8 CALL PRNHEX1 ;affiche le premier morceau POP AF ;r{cup la valeur originale pour la suit PRNHEX1 ;affiche la valeur de A sur 1 chiffre ;affiche A sur 1 chiffre en Hexa AND 0xF ;ne prend que les unit{s OR A DAA ;convertit en d{cimal ADD A,0xF0 ;ajoute 240 ADC A,0x40 ;ajoute 64+le carry (si >15) ;on a le code ascii du chiffre @ afficher JP 0xBB5A ;call-ret ;