; ; Copyright (c) 2009 by Michal Hucik ; ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2 of the License, or ; (at your option) any later version. ; ; MZ-800 Unicard is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with MZ-800 Unicard; if not, write to the Free Software ; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ; ; Ver.: 1.0 ; ; Unicard Example6: ; Vytvoreni souboru do ktereho zapiseme horni ROM Sharpa. ; 9z_504m.bin ; ; porty CMDPORT equ 0x50 DATAPORT equ 0x51 ; prikazy cmdRESET equ 0x00 cmdOPEN equ 0x50 cmdSEEK equ 0x51 cmdCLOSE equ 0x54 ; modus pristupu k souboru ; viz. FatFS - http://elm-chan.org/fsw/ff/en/open.html ; FA_OPEN_EXISTING equ 0x00 FA_READ equ 0x01 FA_WRITE equ 0x02 FA_CREATE_NEW equ 0x04 FA_CREATE_ALWAYS equ 0x08 FA_OPEN_ALWAYS equ 0x10 FILE_SHASCII_CNV equ 0x20 ; kde bude nas program prg_begin: equ 0x2000 org prg_begin - 0x80 ; MZF header db 0x01 db "UNICARD EXAMPLE6",0x0d dw prg_end - prg_begin dw prg_start dw prg_begin db " " db " " db " " db " " db " " db " " db " " prg_start: call 0xEA59 ; smazat obrazovku ; ; reset MZFREPO ; ld a, cmdRESET out (CMDPORT), a ; otevreme soubor ld a, cmdOPEN out (CMDPORT), a ; nastavime modus ; ; Chceme otevrit novy soubor s pristupem ; pro cteni i pro zapis ld a, FA_CREATE_NEW + FA_READ + FA_WRITE out (DATAPORT), a ; Druhym parametrem je jmeno souboru ld hl, filename call SendTxtParam ; Podarilo se nam soubor otevrit? ; ; (Pokud je vse OK, tak ted mame ve statusu nastaveny ; bity READ_FILE, WRITE_FILE a EOF.) ; in a,(CMDPORT) bit 0, a ; je READY ? jp nz, ERROR_PARAM ; NENI: tohle muze nastat jen pokud ; jsme zapomneli ukoncit vkladani ; textoveho parametru znakem mensim jak 0x20 and 0x80 jp nz,ERROR_OPEN ; ne, doslo k chybe pri OPEN ; Nyni mame uspesne otevreny soubor ; ; Predpokladam, ze horni ROM je v tuto chvili namapovana. ; ; Horni ROM je umistena na 0xE000 - 0xFFFF, nicmene ; prvnich 16 bajtu jsou mapovane porty periferii a tak je chceme ; preskocit, proto udelame SEEK o 16 bajtu a zaroven tim zvetsime ; prave otevreny soubor na 16B. (Tech 16B se samozrejme vyplni ; nejakymi nahodnymi daty.) ld a, cmdSEEK out (CMDPORT), a xor a ; rezim=0, tzn, ze seekujeme od zacatku souboru out (DATAPORT),a ; nyni posleme DWORD 0x00000010 v poradi od ; nejnizsiho bajtu k nejvyssimu ld a,0x10 out (DATAPORT),a xor a out (DATAPORT),a out (DATAPORT),a out (DATAPORT),a ; Podaril se nam SEEK ? in a,(CMDPORT) and 0x80 jp nz, ERROR_SEEK ; ne, neco se zvrtlo ; Ted zapiseme horni ROM 0xE010 - 0xFFFF do souboru ld hl, 0xe010 ld c, DATAPORT next_rom_byte: ld a,h ; uz jsme zapsali celou ROM? or l jr z, close_file ; ano, jdeme zavrit soubor outi jr next_rom_byte close_file: ; zavrit soubor ld a, cmdCLOSE out (CMDPORT), a ; HOTOVO, oslavime to blikanim borderu ld bc, 0x06cf next_border: out (c), a inc a jr next_border ; Odeslat data z HL na DATA port. ; Budeme posilat dokud nenarazime na znak 0x00, ktery posleme taky. ; SendTxtParam: ld c, DATAPORT ld e, 0x00 next_SendTxtParam: ld a, (hl) inc hl out (c),a cp e ret z jr next_SendTxtParam filename: db "/9z_504m.bin",0x00 ; Soubor i s cestou (korenovy adresar). ; Take lze pouzit CHDIR / a jmeno ; souboru pak muze byt bez uvedeni ; cesty. msg_err_param: db "ERROR: BAD PARAMETER!",0x0d msg_err_open: db "OPEN - ERROR CODE: ",0x0d msg_err_seek: db "SEEK - ERROR CODE: ",0x0d ERROR_PARAM: ld de, msg_err_param call 0x0015 ; zobrazit text z HL di halt ERROR_OPEN: ld de, msg_err_open jr print_errcode ERROR_SEEK: ld de, msg_err_seek print_errcode: call 0x0015 ; zobrazit text z HL in a,(CMDPORT) ; kod posledniho prikazu in a,(CMDPORT) ; unicard err code in a,(CMDPORT) ; FatFS err code call 0x03c3 ; zobrazit obsah A di halt prg_end: