123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429 |
- /*
- tototek.c - General ToToTEK flash card programmer routines for uCON64
- Copyright (c) 2004 dbjh
- Based on Delphi source code by ToToTEK Multi Media. Information in that source
- code has been used with permission. However, ToToTEK Multi Media explicitly
- stated that the information in that source code may be freely distributed.
- 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.
- This program 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 this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #include <stdlib.h>
- #include "misc/bswap.h"
- #include "misc/misc.h"
- #include "misc/parallel.h"
- #include "misc/term.h"
- #include "backup/tototek.h"
- #ifdef USE_PARALLEL
- static void set_data_read (void);
- //static void set_data_write (void);
- static void set_ai (unsigned char ai);
- static void init_port (void);
- static void deinit_port (void);
- static void end_port (void);
- static void set_addr_read (int addr);
- static void set_addr_write (int addr);
- static unsigned char get_id_byte (unsigned char addr);
- static unsigned short port_8, port_9, port_a, port_b, port_c;
- void
- ttt_init_io (unsigned short port)
- {
- #if (defined __unix__ || defined __BEOS__) && !defined __MSDOS__
- init_conio ();
- #endif
- if (register_func (ttt_deinit_io) == -1)
- {
- fputs ("ERROR: Could not register function with register_func()\n", stderr);
- exit (1);
- }
- port_8 = port; // original code used 0x378 for port_8
- port_9 = port + 1;
- port_a = port + 2;
- port_b = port + 3;
- port_c = port + 4;
- parport_print_info ();
- init_port ();
- }
- void
- ttt_deinit_io (void)
- {
- #if (defined __unix__ || defined __BEOS__) && !defined __MSDOS__
- deinit_conio ();
- #endif
- end_port ();
- deinit_port ();
- }
- static void
- set_data_read (void) // original name: set_data_read
- {
- outportb (port_a, 0); // nastb=1,nib_sel=0,ndstb=1,nwrite=1
- }
- #if 0
- static void
- set_data_write (void) // original name: set_data_write
- {
- outportb (port_a, 1); // nastb=1,nib_sel=0,ndstb=1,nwrite=0
- }
- #endif
- static void
- set_ai (unsigned char ai) // original name: {epp_}set_ai
- {
- outportb (port_a, 1); // set_data_write ()
- outportb (port_b, ai);
- }
- void
- ttt_set_ai_data (unsigned char ai, unsigned char data) // original name: set_ai_data
- {
- set_ai (ai);
- outportb (port_a, 1); // set_data_write ()
- outportb (port_c, data);
- }
- static void
- init_port (void) // original name: init_port
- {
- #ifndef USE_PPDEV
- outportb (port_8 + 0x402, (inportb (port_8 + 0x402) & 0x1f) | 0x80);
- outportb (port_9, 1); // clear EPP time flag
- #endif
- ttt_set_ai_data (6, 0); // rst=0, wei=0(dis.), rdi=0(dis.)
- ttt_set_ai_data (6, 0x84); // rst=1, wei=0(dis.), rdi=0(dis.)
- }
- static void
- deinit_port (void) // original name: Close_end_port
- {
- outportb (port_a, 1);
- outportb (port_b, 0);
- outportb (port_a, 4); // port normal now
- }
- static void
- end_port (void) // original name: end_port
- {
- ttt_set_ai_data (6, 0); // rst=0, wei=0(dis.), rdi=0(dis.)
- outportb (port_a, 4); // set_normal ninit=1, nwrite=1
- }
- void
- ttt_rom_enable (void) // original name: romCS_on
- {
- ttt_set_ai_data (6, 0x84);
- }
- void
- ttt_rom_disable (void) // original name: romCS_off
- {
- ttt_set_ai_data (6, 0x80);
- }
- void
- ttt_ram_enable (void) // original name: ramCS_on
- {
- ttt_set_ai_data (6, 0x88);
- }
- void
- ttt_ram_disable (void) // original name: ramCS_off
- {
- ttt_set_ai_data (6, 0x80);
- }
- static void
- set_addr_write (int addr) // original name: set_Long_adrw
- {
- ttt_set_ai_data (0, (unsigned char) (addr & 0xff)); // a[7..0]
- addr >>= 8;
- ttt_set_ai_data (1, (unsigned char) (addr & 0xff)); // a[15..8]
- addr >>= 8;
- ttt_set_ai_data (2, (unsigned char) (addr & 0xff)); // a[23..16]
- set_ai (3);
- }
- static void
- set_addr_read (int addr) // original name: set_Long_adr
- {
- set_addr_write (addr);
- set_data_read (); // ninit=0, nwrite=1
- }
- void
- ttt_write_mem (int addr, unsigned char b) // original name: WriteMEMb
- {
- set_addr_write (addr);
- outportb (port_c, b);
- }
- static unsigned char
- get_id_byte (unsigned char addr) // original name: GETID
- {
- unsigned char byte;
- ttt_rom_enable ();
- ttt_set_ai_data (0, addr); // a[7..0] = 0
- set_ai (3);
- outportb (port_c, 0x90); // write_data ()
- set_ai (3);
- set_data_read (); // ninit=0, nwrite=1
- byte = inportb (port_c); // read_data ()
- ttt_rom_disable ();
- return byte;
- }
- unsigned short
- ttt_get_id (void) // original name: getIDword
- {
- unsigned short word;
- // eep_reset ();
- word = get_id_byte (0); // msg
- word <<= 8;
- word |= get_id_byte (2); // ID
- return word;
- }
- void
- ttt_read_rom_b (int addr, unsigned char *buf) // original name: read_buffb
- {
- int count;
- ttt_rom_enable ();
- for (count = 0; count < 0x100; count++)
- {
- set_addr_read (addr + count);
- buf[count] = inportb (port_c); // read_data ()
- }
- ttt_rom_disable ();
- }
- void
- ttt_read_rom_w (int addr, unsigned char *buf) // original name: read_buff
- {
- int count;
- set_addr_read (addr);
- for (count = 0; count < 0x80; count++)
- #ifdef WORDS_BIGENDIAN
- ((unsigned short *) buf)[count] = bswap_16 (inportw (port_c)); // read_dataw ()
- #else
- ((unsigned short *) buf)[count] = inportw (port_c); // read_dataw ()
- #endif
- }
- void
- ttt_read_ram_b (int addr, unsigned char *buf) // original name: read_rambuff
- {
- int count;
- ttt_ram_enable ();
- for (count = 0; count < 0x100; count++)
- {
- set_addr_read (addr + count);
- buf[count] = inportb (port_c); // read_data ()
- }
- ttt_ram_disable ();
- }
- void
- ttt_read_ram_w (int addr, unsigned char *buf) // original name: readpagerambuff
- {
- int count;
- set_addr_read (addr);
- for (count = 0; count < 0x80; count++)
- ((unsigned short *) buf)[count] = inportw (port_c);
- // read_dataw (); data is doubled for MD-PRO => no problems with endianess
- }
- // Sharp function
- void
- ttt_erase_block (int addr) // original name: EraseBLOCK
- {
- ttt_rom_enable ();
- ttt_write_mem (addr, 0x50);
- ttt_rom_disable ();
- ttt_rom_enable ();
- ttt_write_mem (addr, 0x20);
- outportb (port_c, 0xd0);
- ttt_rom_disable ();
- ttt_rom_enable ();
- set_ai (3);
- set_data_read (); // set read mode
- while (inportb (port_c) < 0x80)
- ;
- ttt_rom_disable ();
- }
- void
- ttt_write_byte_sharp (int addr, unsigned char b) // original name: writeEEPDataB
- {
- ttt_rom_enable ();
- ttt_write_mem (addr, 0x40);
- outportb (port_c, b);
- ttt_rom_disable ();
- }
- void
- ttt_write_byte_intel (int addr, unsigned char b) // original name: writeIntelEEPDataB
- { // MD-PRO function
- ttt_rom_enable ();
- ttt_write_mem (addr, 0x40);
- outportb (port_c, b);
- set_data_read ();
- while (inportb (port_c) < 0x80)
- ;
- ttt_rom_disable ();
- }
- void
- ttt_write_page_rom (int addr, unsigned char *buf) // original name: writeEEPDataPAGE
- {
- int i;
- // send command 0xe8
- ttt_rom_enable ();
- ttt_write_mem (addr, 0xe8);
- // read status
- set_ai (3);
- set_data_read ();
- while (inportb (port_c) < 0x80)
- ;
- set_ai (3);
- outportb (port_c, 0x1f);
- ttt_set_ai_data (6, 0x94);
- set_addr_write (addr);
- for (i = 0; i <= 0x1f; i++)
- outportb (port_c, buf[(addr + i) & 0x3fff]);
- ttt_set_ai_data (6, 0x84);
- set_ai (3);
- outportb (port_c, 0xd0);
- // read status
- set_ai (3);
- set_data_read ();
- while (inportb (port_c) < 0x80)
- ;
- ttt_rom_disable ();
- }
- void
- ttt_write_byte_ram (int addr, unsigned char b) // original name: writeRAMDataB
- {
- ttt_ram_enable ();
- ttt_write_mem (addr, b);
- ttt_ram_disable ();
- }
- void
- ttt_write_page_ram (int addr, unsigned char *buf) // original name: writeRAMDataPAGE
- {
- int i;
- ttt_ram_enable ();
- ttt_set_ai_data (6, 0x98);
- set_addr_write (addr);
- for (i = 0; i < 0x100; i++)
- outportb (port_c, buf[(addr + i) & 0x3fff]);
- ttt_ram_disable ();
- }
- void
- ttt_write_page_ram2 (int addr, unsigned char *buf) // original name: writeRAMDBDataPAGE
- { // MD-PRO function
- int i;
- ttt_ram_enable ();
- ttt_set_ai_data (6, 0x98);
- set_addr_write (addr * 2);
- for (i = 0; i < 0x80; i++)
- {
- outportb (port_c, buf[(addr + i) & 0x3fff]);
- outportb (port_c, buf[(addr + i) & 0x3fff]);
- }
- ttt_ram_disable ();
- }
- #if 0
- void
- readstatus (void)
- { // MD-PRO function
- // send command 0xe8
- ttt_rom_enable ();
- set_ai (3);
- set_data_read ();
- while (inportb (port_c) < 0x80)
- ;
- ttt_rom_disable ();
- }
- #endif
- #endif // USE_PARALLEL
|