define zxdos 1 IF zxdos=1 output BACKZX2 ELSE output BACKZXD ENDIF include zxuno.inc org $2000 ; comienzo de la ejecución de los comandos ESXDOS call wrear0 dec b out (c), 0 inc b in f, (c) jp p, Nonlock call Print dz 'ROM not rooted' ret Nonlock wreg flash_cs, 0 ; activamos spi, enviando un 0 wreg flash_spi, $9f ; jedec id in a, (c) in a, (c) in a, (c) in a, (c) wreg flash_cs, 1 ; desactivamos spi, enviando un 1 sub $19 jr z, Goodflsh call Print dz 'Incorrect flash IC' ret Goodflsh ld a, scandbl_ctrl dec b out (c), a inc b in a, (c) and $3f ld (normal+1), a or $c0 out (c), a call init ld bc, zxuno_port ld a, scandbl_ctrl out (c), a inc b normal ld a, 0 out (c), a ret init xor a esxdos M_GETSETDRV ; A = unidad actual jr nc, SDCard call Print dz 'SD card not inserted' ret SDCard ld b, FA_WRITE | FA_OPEN_AL ; B = modo de apertura ld hl, FileName ; HL = Puntero al nombre del fichero (ASCIIZ) esxdos F_OPEN ld (handle+1), a jr nc, FileFound call Print IF zxdos=1 dz 'Can\'t open FLASH.ZX2' ELSE dz 'Can\'t open FLASH.ZXD' ENDIF ret FileFound call Print IF zxdos=1 dz 'Backing up FLASH.ZX2 to SD', 13 ELSE dz 'Backing up FLASH.ZXD to SD', 13 ENDIF call write16m wreg flash_cs, 0 ; activamos spi, enviando un 0 wreg flash_spi, 6 ; envío write enable wreg flash_cs, 1 ; desactivamos spi, enviando un 1 wreg flash_cs, 0 ; activamos spi, enviando un 0 wreg flash_spi, $c5 ; envío wrear ld l, 1 out (c), l wreg flash_cs, 1 ; desactivamos spi, enviando un 1 call write16m esxdos F_CLOSE call Print dz 13, 'Backup complete' wrear0 wreg flash_cs, 0 ; activamos spi, enviando un 0 wreg flash_spi, 6 ; envío write enable wreg flash_cs, 1 ; desactivamos spi, enviando un 1 wreg flash_cs, 0 ; activamos spi, enviando un 0 wreg flash_spi, $c5 ; envío wrear out (c), 0 wreg flash_cs, 1 ; desactivamos spi, enviando un 1 ret write16m ld hl, $0000 Bucle push hl ld de, $8000 ld a, $40 call rdflsh add hl, hl add hl, hl ld a, h and $3f jr nz, punto ld a, 'o' rst $10 punto ld hl, $8000 ld bc, $4000 handle ld a, 0 esxdos F_WRITE pop hl jr nc, WriteOK call Print dz 'Write Error' ret WriteOK ld de, $0040 adc hl, de jr nc, Bucle ret Print pop hl db $3e Print1 rst $10 ld a, (hl) inc hl or a jr nz, Print1 jp (hl) ; ------------------------ ; Read from SPI flash ; Parameters: ; DE: destination address ; HL: source address without last byte ; A: number of pages (256 bytes) to read ; ------------------------ rdflsh ex af, af' xor a push hl wreg flash_cs, 0 ; activamos spi, enviando un 0 wreg flash_spi, 3 ; envio flash_spi un 3, orden de lectura pop hl push hl out (c), h out (c), l out (c), a ex af, af' ex de, hl in f, (c) rdfls1 ld e, $20 rdfls2 ini inc b ini inc b ini inc b ini inc b ini inc b ini inc b ini inc b ini inc b dec e jr nz, rdfls2 dec a jr nz, rdfls1 wreg flash_cs, 1 pop hl ret rst28 ld bc, zxuno_port + $100 pop hl outi ld b, (zxuno_port >> 8)+2 outi jp (hl) IF zxdos=1 FileName dz 'FLASH.ZX2' ELSE FileName dz 'FLASH.ZXD' ENDIF