General Notice When using this document, keep the following in mind: ntial 1. This document is confidential. By accepting this document you acknowledge that you are bound by the terms set forth in the non-disclosure and confidentiality agreement signed separately and /in the possession of SEGA. If you have not signed such a non-disclosure agreement, please contact SEGA immediately and return this document to SEGA. 2. This document may include technical inaccuracies or typographical errors. Changes are periodi- cally made to the information herein; these changes will be incorporated in new versions of the program(s) described in this document at any time. de document. SEGA may make improvements and/or changes in the product(s) and/or the 3. No one is permitted to reproduce or duplicate, in any form, the whole or part of this document without SEGA’S written permission. Request for copies of this document and for technical information about SEGA products must be made to your authorized SEGA Technical Services representative. nfi 4. No license is granted by implication or otherwise under any patents, copyrights, trademarks, or other intellectual property rights of SEGA Enterprises, Ltd., SEGA of America, Inc., or any third party. describe herein. Co 5. Software, circuitry, and other examples described herein are meant merely to indicate the character- istics and performance of SEGA’s products. SEGA assumes no responsibility for any intellectual property claims or other problems that may result from applications based on the examples 6. It is possible that this document may contain reference to, or information about, SEGA products (development hardware/software) or services that are not provided in countries other than Japan. Such references/information must not be construed to mean that SEGA intends to provide such SEGA products or services in countries other than Japan. Any reference of a SEGA licensed prod- GA uct/program in this document is not intended to state or simply that you can use only SEGA’s licensed products/programs. Any functionally equivalent hardware/software can be used instead. 7. SEGA will not be held responsible for any damage to the user that may result from accidents or any other reasons during operation of the user’s equipment, or programs according to this document. NOTE: A reader's comment/correction form is provided with this document. Please address comments to : SE SEGA of America, Inc., Developer Technical Support (att. Evelyn Merritt) 150 Shoreline Drive, Redwood City, CA 94065 SEGA may use or distribute whatever information you supply in any way it believes appropriate without incurring any obligation to you. (6/27/95- 002) TM ntial de nfi Co GA SATURN System Library User's Guide SE ver. 1.0 Doc. # ST-162-R1-092994 © 1994-95 SEGA. All Rights Reserved. READER CORRECTION/COMMENT SHEET Keep us updated! nti If you should come across any incorrect or outdated information while reading through the attached document, or come up with any questions or comments, please let us know so that we can make the al required changes in subsequent revisions. Simply fill out all information below and return this form to the Developer Technical Support Manager at the address below. Please make more copies of this form if more space is needed. Thank you. General Information: Your Name Phone Document number Document name Corrections: Chpt. pg. # ST-162-R1-092994 de Saturn System Library User's Guide, ver. 1.0 Correction Date nfi Co GA Questions/comments: SE Fax: Where to send your corrections: (415) 802-1717 Attn: Evelyn Merritt, Developer Technical Support Mail: SEGA OF AMERICA Attn: Evelyn Merritt, Developer Technical Support 150 Shoreline Dr. Redwood City, CA 94065 REFERENCES with the assistance of the technical literature listed below. nti In translating/creating this document, certain technical words and/or phrases were interpreted 1. KenKyusha New Japanese-English Dictionary 1974 Edition al 2. Nelson’s Japanese-English Character Dictionary 2nd revised version 3. 4. Microsoft Computer Dictionary Japanese-English Computer Terms Dictionary Nichigai Associates 4th version de nfi Co GA SE Table of Contents SYSTEM PROGRAM USER’S MANUAL .................................................... 1 1.0 2.0 nti GUIDE ............................................................................................... 1 al 1.1 Explanation .............................................................................. 1 REFERENCE .................................................................................... 7 2.1 List of Functions ...................................................................... 7 2.2 Function Specifications ............................................................ 8 SMPC I/F USER’S MANUAL .................................................................... 15 1.0 2.0 3.0 de GUIDE ............................................................................................. 15 FEATURES ..................................................................................... 15 OVERVIEW ..................................................................................... 16 3.1 Function Overview ................................................................. 16 3.2 Process Overview .................................................................. 16 4.0 5.0 nfi DETAILS ......................................................................................... 17 4.1 Functions ............................................................................... 17 4.2 Process ................................................................................. 18 4.3 Peripheral Control .................................................................. 22 CALLING SEQUENCE .................................................................... 23 6.0 7.0 Co DATA SPECIFICATIONS................................................................. 24 6.1 List of Data ............................................................................ 24 6.2 Data Specifications ................................................................ 25 FUNCTION SPECIFICATIONS ....................................................... 33 7.1 List of Functions .................................................................... 33 7.2 Function Specifications .......................................................... 33 GA BACKUP LIBRARY USER’S MANUAL ..................................................... 39 1.0 Guide .............................................................................................. 39 2.0 1.1 Purpose ................................................................................. 39 1.2 Explanation ............................................................................ 39 1.3 Program Example .................................................................. 40 Reference........................................................................................ 41 2.1 Data List ................................................................................ 41 SE 2.2 Function List .......................................................................... 42 2.3 Data Flow .............................................................................. 43 2.4 Function Specification ........................................................... 43 System Program User’s Manual 1.0 Guide 1.1 Explanation ntial Interrupt Process Routine Registration and Reference Operations After booting up from the boot ROM, the master SH2 interrupt vector table is at the beginning of the work RAM, and the VBR (vector base register) indicates this ad- dress. The slave SH2 interrupt vector table is the work RAM lead + 400H, and the slave de SH2 VBR indicates that address. The interrupt vector (programmable) of every built-in SH2 module is assigned by the initial settings in the table below. Dummy routines that do nothing are set in the vector table. (With the exception of invalid commands and address errors, these are infinite loops.) The FRT input capture interrupt is assigned for use in master and slave communica- tions, and its initial priority is 15 (highest priority). In the table below, the priority of unauthorized. nfi all interrupts, except for the FRT input capture interrupt, is set at 0 and interrupt is In changing the priority of the built-in module interrupts, the content of the inter- rupt control register must change in response to the needs of the application. Co Master SH2 Vector Initial Settings 40H ~ SCU interrupt vector 5FH (set by hardware) 60H SCI receive error 61H SCI receive buffer full 62H SCI send buffer empty 63H SCI send quit Slave SH2 Vector Initial Settings 41H H-Blank In * * 43H V-Blank In 60H SCI receive error 61H SCI receive buffer full 62H SCI send buffer empty 63H SCI send quit * 64H FRT input capture * 64H FRT input capture 65H FRT compare match 65H FRT compare match 66H FRT overflow 66H FRT overflow GA 67H Free 68H WDT interval 69H BSC compare match 6AH Free 6BH Free 6CH DMACH1 (SH2 built-in) 6DH DMACH0 (SH2 built-in) 6EH DIVU (division) 6FH Free 67H free 68H WDT interval 69H BSC compare match 6AH Free 6BH Free 6CH DMACH1 (SH2 built-in) 6DH DMA CH0 (SH2 built-in) 6EH DIVU (division) 6FH Free SE * for slave > master passing * for master > slave passing * * IRL2, IRL6 level interrupts Saturn System Library User's Guide 1 This operation routine should be used to register the interrupt process routine to the interrupt vector and to reference the address of the current process routine. Further- more, a SCU interrupt routine (the master SCU interrupt) that implements the inter- nti rupt process via a format that subroutine calls the C function is provided. The C function can be registered there and the registration address can also be referenced. al The function registered in the SCU interrupt routine is called whenever interrupt occurs. Before and after this call, register save and return are performed per register retention (save) protocol of the SHC compiler. If the routine is one that complies with the C function or that protocol, it can be registered and processed. If a separate interrupt process routine is registered in the SCU interrupt vector, the SCU interrupt process routine is bypassed and becomes invalid. However, it may not be suitable for an interrupt process requiring a rapid response such as HBlank. de SCU Interrupt Mask Set, Reference, and Change Operations Because this register cannot be read, the mask value set to the SCU interrupt mask register cannot perform computation against the actually set values when changes, etc. are implemented. Therefore, this value is stored separately in memory and a service routine, which preserves and updates in consistency with the actual SCU interrupt mask register, is provided. nfi When this routine is used, setting and changing the SCU interrupt mask must al- ways be done by the library and application through these functions. After the SCU interrupt mask register is set and changed, the SCU interrupt status register, and if necessary, the A-Bus interrupt acknowledge register, are cleared. Simple Semaphore Operation Co A service is available that enables memory (256 bytes) provided by the Boot ROM to be used as 256 bytes of simple semaphore. The first half (numbers 0 ~ 127) of sema- phore can be used in any way. The second half (128 ~ 255) is used in operations related to the library. When the library uses a specific function such as DMA, it sets semaphore MSB(80H) to 1 and shows that it is in use. After that, it clears MSB and shows that it is free. GA In a process that requires resources to be secured over a comparatively long period of time, the semaphore operation and reference procedure should be determined so that those resources are not accessed arbitrarily by an interrupt process during that period of time. The SH2 TAS command is used when setting MSB for semaphore memory. This command allows only one process to reliably acquire semaphore since execution is indivisible (bus control [authorization] is not cleared). This must be cleared when SE the process that acquired semaphore is completed. All semaphore memory is cleared when reset. 2 System Clock Switching System clock switching cannot be performed by issuing independent commands to the SMPC. Use of this system program is required. System clock switching entails a partial hardware reset. CPU Clock Horizontal Resolution 26 MHz 320/640 ←→ ←→ nti 28 MHz al 352/704 Reset Devices OFF or non guaranteed Devices Unaffected Devices SCU Slave SH (OFF) Master SH * note VDP1 DRAM (previous content destroyed) SDRAM VDP2 SCSP (OFF) CD SCSI/SCC (development devices only) de SIMM (development devices only) * Note Because master SH is in the standby mode during clock switching, of the built-in SH modules, the FRT and the SCI within the SH must be reset. WDT is used during this process. NMI goes to its existed status after the process; for example, the DMAC control goes to inter- rupt status by NMI. See the SH manual. If necessary, perform the reopen process. Reinitializing process after reset: SCU: nfi Reinitializes the bus, interrupt mask, etc. However, the value of SYS_GETSCUIM is used for the interrupt mask value. Postprocesses required with applications: VDP2: Co The TV mode must be set comparatively fast. Because the 320/640 mode is used after the device itself is reset, especially when the system clock is changed to the 352/704 mode, the synchronous signal shifts in the TV and turbulence occurs on the screen. VDP1, 2, SCSP: All previous settings are invalid. Must be reset. SMPC: Hot reset must be enabled. GA The clock change process time is about 110 ms, which includes the reset time of the device. SE Saturn System Library User's Guide 3 SCU Interrupt Routine Priority Change The Boot ROM has an interrupt priority control table used for the SCU interrupt process service, making rewrite possible. Note: nti This is a risky service. The system may hang up if priority relationship inconsistencies exist in the table contents. al With this, the interrupt process (items using SYS_SETUINT) can be optimized in the application. To use this, prepare the same structural data for the application as the table, and call SYS_CHGUIPR. Tables are of 32 long words. 1 long word has the following contents. SH2 SR insignificant word value The value set to SR at the beginning of the interrupt process de SCU interrupt mask insignificant word value ORed with the current mask set value and written to the SCU interrupt mask correspond to vectors 4EH and 4FH are included.) nfi register at the beginning of the interrupt process. This long word position inside the table corresponds to the SCU 30 interrupt factor. (V-Blank In is the start and V-Blank Out is the 2nd,…but 2 long word spaces that Uint32 PRITab[32] = { Co Tables must be created very carefully so that there is no inconsistency between the SR, SCU interrupt mask, and interrupt factor. For example, the Boot ROM uses the following table for its initial set values: 0x00F0FFFF, /* VBI SR=15 All prohibited (highest priority) */ 0x00E0FFFE, /* VBO SR=14 Only VBI is allowed */ 0x00D0FFFF, /* HBI SR=13 VBI and VBO are allowed */ } ; 0x0070FE00, GA . . /* External 15 SR=7 SCU interrupt unique priority; all masked when 7 or less. */ /* A bus interrupt unique priority that assumes 7, 4,and 1 by cause factor, but because of the common use and 1 bit mask, it is set to 7. */ SE 4 The creation example shown is one in which the SR value is always set to 0, and priorities are described only using SCU mask values (priority relationship). Here, SH always receives an interrupt and only the SCU mask controls authorization and prohibition. Uint32 PRITab[32] = { 0x0000FFF9, 0x0000FFFB, 0x00D0FFFC, ntial /* during VBI process HBI and VBO authorization /* during VBO process only HBI authorization /* during HBI process all prohibited (highest priority) . . */ */ */ 0x00000000, /* during external 15 process, all authorized (lowest priority) */ } ; The inverse of the example above is prohibiting mask interrupt at SR value levels without prohibition. de changing the SCU mask value. (0 or 15 only are possible.) In the example above, the interrupt authorize and prohibit register of each built-in module must also be operated for SH internal module interrupt authorization and Note: nfi When the SCU factor interrupt is allowed and interrupt occurs, it is okay if the SH SR mask is higher than the interrupt unique level (value decided by SCU hardware) and if interrupt can never be refused by SH. (However, one exception is that all of SR mask 15 can be prohibited.) CD Multiplayer Startup Execution This is a service that activates and executes the CD multiplayer when an application Co ends. When this service is called, the CD multiplayer screen is displayed exactly the same as when the power-on sequence is activated. Regardless of the called status, the CD multiplayer screen is displayed and operation is enabled. Power On Clear Memory Operation This provides the 8 bytes of memory on the SDRAM controlled by the Boot ROM. The 8 bytes are initialized to 0 when power-on is activated, but the contents can be saved with the reset button (NMI). GA SE Saturn System Library User's Guide 5 (This page is blank in the original Japanese document.) ntial de nfi Co GA SE 6 2.0 Reference 2.1 List of Functions Function Interrupt Process Routine Registration / Reference Registers process routine to the interrupt vector Registers function to SCU interrupt routine Gets registration contents of interrupt vector ntiFunction Name al SYS_SETSINT SYS_SETUINT SYS_GETSINT No. 1.1 1.2 1.3 Gets registration contents of SCU interrupt SYS_GETUINT 1.4 routine SCU Interrupt Mask Set, Reference, and Change Operations Sets SCU interrupt mask Changes SCU interrupt mask References SCU interrupt mask Simple Semaphore Operation Gets semaphore de SYS_SETSCUIM SYS_CHGSCUIM SYS_GETSCUIM SYS_TASSEM 2.1 2.2 2.3 3.1 Clears semaphore System Clock Switching Switches system clock nfi References system clock value SCU Interrupt Routine Priority Change SYS_CLRSEM SYS_CHGSYSCK SYS_GETSYSCK 3.2 4.1 4.2 Co Changes SCU interrupt routine priority CD Multi-player Startup Execution Executes startup of CD multi-player Power On Clear Memory Operation Operates power-on clear memory SYS_CHGUIPR SYS_EXECDMP SYS_PCLRMEM 5.1 6.1 7.1 GA SE Saturn System Library User's Guide 7 2.2 Function Specifications nti Title Function Function Name No. Function To the interrupt vector; registers interrupt process SYS_SETSINT 1.1 Specifications routine Format: Input: Output: Function Value: void SYS_SETSINT (Uint 32 Num, void* Num : vector number (0..7FH) al Hdr); Hdr : interrupt process routine address (dummy routine when 0, None None or that interrupt process routine when Num is the SCU interrupt vector) Function: de Hdr must be a process routine that ends by register save, return, and RTE command (# pragma interrupt is added if using C language ). When Hdr is 0, Num re-registers the SCU interrupt routine within the SCU interrupt (40H..4DH,50H..5FH), others register dummy routine. There is no range check. Values beyond restricted range must not be specified. Remarks: Title Function Specifications Function nfi This routine can be used with both master and slave SH2 and is registered to vector addresses based on each VBR. To SCU interrupt routine; registers process function Function Name SYS_SETUINT No. 1.2 Format: Input: Output: Function Value: Function: Co void SYS_SETUINT (Uint 32 Num, void* Num : vector number (SCU vector number) Hdr : function routine address (dummy routine when 0) None None Hdr); Hdr must be a function by SHC. If the routine is created by the assembler, it must follow the SHC register save protocol. Num is limited to SCU interrupt vectors (40H..4DH,50H..5FH). GA A dummy routine is registered when Hdr is 0. There is no range check. Values beyond restricted range must not be specified. Remarks: When a routine is registered to a vector by SYS_SETSINT, the SCU interrupt process routine of that vector becomes ineffective and the registration function is not called. Results are not guaranteed when this routine is called via SH2 slave. SE 8 Title Function Function Name No. Function Gets registration contents of interrupt vector SYS_GETSINT 1.3 Specifications Format: Input: Output: Function Value: Function: void (*) () nti SYS_GETSINT (Uint 32 Num) ; Num : vector number (0..7FH) None al Vector registration contents (interrupt process routine address) Contents of the Num vector returned as function values. There is no range check. Values beyond restricted range must not be specified. Remarks: This routine can be used with both master and slave SH2 and refers to the vector addresses based on each VBR. Title Function Specifications Format: Input: Output: Function de Gets registration contents of SCU interrupt routine void (*) () Function Name SYS_GETUINT SYS_GETUINT (Uint 32 Num) ; Num : vector number (SCU vector number) None No. 1.4 Function Value: Function: Remarks: nfi Registration contents (function routine address) The registration contents of the SCU interrupt routine that pertains to Num returned as function values. There is no range check. Values beyond restricted range must not be specified. Results are not guaranteed when this routine is called via slave SH2. Title Function Specifications Format: Input: Co Function Sets SCU interrupt mask void SYS_SETSCUIM (Uint 32 MaskPat : SCU interrupt mask value Function Name SYS_SETSCUIM MaskPat) ; No. 2.1 Output: None Function Value: None Function: Writes the MaskPat value to mask save memory and to the SCU GA Remarks: interrupt register, and then writes the same value to the SCU interrupt status register. However, if the A-bus interrupt mask bit is allowed, the upper word of the status register is cleared, and the A-bus inter- rupt acknowledge register is cleared as well. This routine must not be used from the interrupt process (for SCU interrupt only) (The value of SYS_GETSCUIM becomes undefined during the SCU interrupt process.) The SCU interrupt may disappear when it occurs during the process SE (SCU specifications). This possibility should either be avoided or the usage should occur under conditions where there is no related knowl- edge thereof. Results cannot be guaranteed when this routine is called via slave SH2. Saturn System Library User's Guide 9 Title Function Function Name No. Function Changes SCU interrupt mask SYS_CHGSCUIM 2.2 Specifications Format: Input: Output: Function Value: Function: void SYS_CHGSCUIM (Uint 32 AndMask OrMask None None AndMask, Uint32 : Mask value used for authorizing : Mask value used for denying ntial OrMask) ; Takes the logical product of the contents of the mask memory and the AndMask and writes the result of the logical sum of that and the Or- Mask to the mask save memory and the SCU interrupt. However, if the A-bus interrupt mask bit is allowed, the upper word of the status register is cleared, and the A-bus interrupt acknowledge register is Remarks: de cleared as well. These operations are executed inseparably. This routine must not be used from the interrupt process (for SCU interrupt only) (The value of SYS_GETSCUIM becomes undefined during the SCU interrupt process.) The SCU interrupt may disappear when it occurs during the process (SCU specifications). This possibility should either be Title nfi avoided or the usage should occur under conditions where there is no related knowledge thereof. Results cannot be guaranteed when this routine is called via slave SH2. Function Function Name No. Function Specifications Format: Input: Output: Function Value: Co References SCU interrupt mask value Uint 32 None None SYS_GETSCUIM ; Mask save memory value SYS_GETSCUIM 2.3 Function: This function reads the mask save memory value. If this value performs settings and changes of the SCU interrupt mask register using the aforementioned function, it is the same as the value actually Remarks: GA set in the SCU interrupt mask register. During the SCU interrupt process, the change is made to the value that is set when the application uses SYS_SETSCUIM () and SYS_CHGSCUIM () where the change is made to the logical sum of the mask value by interrupt cause factor (when the application uses SYS_CHGUIPR() and setting has been made, the corresponding values within that table). However, the interrupt becomes multi-level and changes to the logical sum. Consequently, this value becomes SE undefined during the SCU interrupt process. During this procedure, a process that relies on referenced values should not be performed. 10 Title Function Function Name No. Function Gets semaphore SYS_TASSEM 3.1 Specifications Format: Input: Output: Function Value: Function: Uint 32 SYS_TASSEM (Uint 32 Num : semaphore number (0 ~ FFH) None ntiNum) ; al Result (1: acquired, 0: already acquiring another) TAS command to memory (1 byte) linked to Num number is executed and the results are returned to function values. There is no range check. Values beyond the restricted range must not be specified. This routine can be used with both master and slave SH2. Title Function Specifications Format: Input: Output: Function Clears semaphore void Num None de SYS_CLRSEM (Uint 32 Function Name SYS_CLRSEM Num) ; : semaphore number (0 ~ FFH) No. 3.2 Function Value: Function: None nfi Clears the memory (1 byte) linked to Num number. There is no range check. Values outside restrictions must not be specified. This routine can be used with both master and slave SH2. Title Function Specifications Format: Input: Co Function Switches System Clock void SYS_CHGSYSCK (Uint 32 CkMode: 0: CPU 26 MHz, 320/640 Mode Function Name SYS_CHGSYSCK CkMode) ; 1: CPU 28 MHz, 352/704 Mode No. 4.1 Output: None Function Value: None GA Function: System clock is switched to the value specified by CkMode. Remarks: See the overview and the SMPC Manual regarding reset devices and processing time. The system hangs up when this routine is called via slave SH2. Be sure to call via master SH2. SE Saturn System Library User's Guide 11 Title Function Function Name No. Function References System Clock Value SYS_GETSYSCK 4.2 Specifications Format: Input: Output: Function Value: Function: Uint 32 None None SYS_GETSYSCK ; 0 or 1: the final SYS_CHGSYSCK () parameter value Reads the system clock value. Parameter value when SYS_CHGSYSCK () is called for the last time. ntial Remarks: Please reference this value via master SH2. Title Function Function Name No. Function Specifications Format: Input: Output: Function Value: Function: Change SCU Interrupt Routine Priority void IprTab None None SYS_CHGUIPR (Uint 32 : 32 long word data array de SYS_CHGUIPR *IprTab) ; 5.1 The SCU interrupt routine priority table of the Boot ROM is rewritten Note: factor. nfi as the table value specified by IprTab. If rewrite is performed once, interrupt processing by the SCU interrupt routine is executed in accordance with the priority of the table values pertaining to each The table contents are not checked. If inconsistencies relating to priority exist in the table, the Remarks: system may hang up. Co Table settings are valid until the next rewrite. During this interval, there is no need for the application to save the table specified in the parameters. Further, reset returns to the initial set value of the Boot ROM. The results cannot be guaranteed when this routine is called via slave SH2. Title Function Function Name No. Function Specifications Format: Input: Output: Function Value: Function: GA Starts and Executes CD Multiplayer void None SYS_EXECDMP (void) ; Does not return to call side. None Starts and executes the CD multiplayer. SYS_EXECDMP 6.1 Remarks: The system hangs up when this routine is called via slave SH2. SE Be sure to call via master SH2. 12 Title Function Function Name No. Function Operates Power On Clear Memory SYS_PCLRMEM 7.1 Specifications Format: Input: Output: Function Value: Function: Uint8 *SYS_PCLRMEM Perform normal memory access. Perform normal memory access. None ntial 8 byte memory address controlled by the Boot ROM. This memory is initialized to 0 only when the power is turned on, but the contents are saved by the reset button (NMI). Remarks: A check of the range is not performed. Be careful not to access outside the range. de nfi Co GA SE Saturn System Library User's Guide 13 (This page is blank in the original Japanese version.) ntial de nfi Co GA SE 14 SMPC I/F User’s Manual 1.0 Guide ntial This library uses functions of the SMPC (System Management and Peripheral Con- trol). 2.0 Features • Able to greatly decrease the main CPU burden. SMPC register. de • The main CPU and SMPC interface is a software handshake method using the nfi Co GA SE Saturn System Library User's Guide 15 3.0 Overview 3.1 Function Overview control system. nti SMPC functions can be divided into the system management system and peripheral • System Management System al The system management system resets the hardware (CPU, sound, etc.), sets the clock, and performs acquisition. • Peripheral Control System The peripheral control system collects data automatically from peripherals con- 3.2 Process Overview de nected to the peripheral I/F, and returns it to the main CPU. The interface between the SMPC and the main CPU is a handshake. In executing a function (command), required parameters are written to the SMPC register. The command write procedure is followed. SMPC executes processing in response to IntBack. nfi commands when commands are written. Processes include IntBack and Non- • IntBack Intback is the process of returning results through interrupts (SMPC interrupts) • Non-IntBack Co after commands are passed to the SMPC. SMPC interrupt processing and regis- tration are performed in the library. Also, other interrupt processes are prohib- ited during the SMPC interrupt process. Timing of issuing command issuance differs according to the function. Non-IntBack is a process that only passes commands to the SMPC. The library function waits for the SMPC process to end. (See the SMPC User’s Manual for details of each SMPC process time.) The functions (reset, etc.) that can be used GA by this process are functions which do not have to receive results after a com- mand has been passed. Shown below are the processing systems that can be used by each function. O : Processing, X : Not processing IntBack Non-IntBack SE System Management Peripheral Control O O O X 16 4.0 Details 4.1 Functions • System Management System The system management system has the following functions. Function Master SH2 ON IntBack X ntialNon-IntBack O Slave SH2 ON X O Slave SH2 OFF X O Sound ON X O Sound OFF CD ON CD OFF Entire system reset NMI Request Hot reset enable de X X X X X X O O O O O O Hot reset disable Get cartridge code Get area code Get system status Set SMPC memory nfi O X O O X O X X X O Set time Co Get SMPC memory Get time O O X X O X (Note) Clock change 320,352 is provided by the system library. • Peripheral Control System GA The following peripherals are supported by the library. Game Device Peripheral Name Saturn Peripherals Digital Devices Analog Devices Pointing Devices (mouse) Keyboard Multitap (6P) SE Mega Drive Peripherals 3-button Pad 6-button Pad 4P adapter Mouse Saturn System Library User's Guide 17 4.2 Process 4.2.1 Library Configuration • Non-IntBack Command Issuance This is the Non-IntBack system process. • IntBack Command Issuance Gets system data (except for time) ntial This process is performed once per game. Gets peripheral data and time data This is a process required for each frame. 4.2.2 Recommended Examples Recommended examples of three patterns are shown below. Non-IntBack Command Issuance de 1 2 O 3 IntBack Commnad Issuance Get system data Get peripheral data nfi Get peripheral data and time data O O O O O O Co GA SE 18 • Chart Descriptions Main Process IntBack initialization (1) : Specifies system data acquisition acquisition nti IntBack initialization (2) : Specifies peripheral data acquisition IntBack initialization (3) : Specifies peripheral data acquisition and time data SMPC Process (1) : System data collection process al (2) : Peripheral data collection process (3) : Time data collection process (1) Pattern 1 de nfi Co GA * * SE Saturn System Library User's Guide 19 ntial de nfi 4.2.3 • Common Restrictions Co • Do not issue commands after V-Blank IN until 300 µs has elapsed. • Do not issue commands after issuing the IntBack command until the next V-Blank IN. GA • Cautions when executing in multiple tasks In cases in which the interrupt task is changed when using the library with multiple tasks, because SMPC exclusive control is not performed in the library, SMPC deadlock may occur and SMPC operation may become abnormal. As a result, when executing with multiple tasks, the exclusive control of library must be performed by the user. • For restrictions from slave SH2 see the SMPC User’s Manual. SE • Command process time may vary between 20 µs to 100 µs, because there is 1 SMPC internal process per second. • Non-IntBack Command Issue Function • There are no restrictions other than Common (above). 20 • IntBack Command Issue Function System Data Acquisition (Excluding time) Peripheral Data Acquisition, Time Data Acquisition nti • There are no restrictions other than Common (above). al • Do not issue a command after issuing the IntBack command until the next V-Blank IN. • Issue a IntBack command 14 ms before the specified V-Blank IN. • The peripheral data collection process within SMPC is done during one vertical display period. • (Time out) data that could not be acquired at the instructed V-Blank IN after the IntBack command is issued cannot be acquired thereafter. • Number of V-Blank IN Skips de • If a time out frequently occurs, peripherals are handled as unconnected. • In SMPC, peripheral acquisition begins in such a way that the peripheral acquisiton ends 1ms before the specified V-Blank. The number of V-Blank skips indicates the execution timing of the peripheral data collection process in SMPC after the IntBack command is issued. This is nfi provided for games that change frames by 2 frames or more. The peripheral data collection process in SMPC is executed in V-DISP before the (V-Blank In skip number + 1)th V-Blank IN after the IntBack command is issued . Set 0 when executing in V-Blank IN immediately after issuing the IntBack command. Co GA SE Saturn System Library User's Guide 21 4.3 Peripheral Control Peripheral controls must be created in accordance with game creation standards. 4.3.1 nti The library is created intelligently, thus enabling them to be created easily. Policy al The peripheral acquisition process is created according to the following policies for flexible response to the user. • Able to accommodate peripherals to be sold in the future. • Methods that do not provide multitap awareness. • Perform corrective measures against problems. 4.3.2 Method (1) Overview de • Each peripheral IDs and peripheral data is obtained by specifying as inputs the required number of peripherals, peripheral IDs and preferred size. • Even when the peripheral acquisition ID and connected peripheral ID are different, data is obtained if peripherals are connected. For example, analog device data is obtained as mouse data. (Example) Input Required number of peripherals = 3 Peripheral ID = digital device nfi Connection Status Co Peripheral size = digital device size Main connector 1 = multi-tap 6P Multi-tap connector 1 = digital device Multi-tap connector 3 = analog device Main connector 2 = keyboard device (Other devices are not connected to peripherals) GA Output Peripheral ID Peripheral Data No. 1 Digital Digital Format No. 2 Unconnected Invalid No. 3 Analog Digital Format SE 22 5.0 Calling Sequence Recommended example of pattern 3 calling sequence. Uint32 work[10]; PerGetSys *sys_data; PerDgtInfo *get_per; Uint8 *get_tim; /* /* /* /* peripheral data acquisition work area system data ntial peripheral output data pointer time output data pointer */ */ */ */ • Initial Process (Immediately after the V-Blank Process). PER_Init (PER_KD_SYS, 0, 0, 0, NULL, 0); /* get system data is specified*/ . . . sys_data = PER_GET_SYS () ; de • Normal (Immediately after the V-Blank Process). /* get system data PER_Init (PER_KD_PERTIM, 3, PER_ID_DGT, PER_SIZE_DGT, work, 0); /* Peripheral data and time data acquisition are specified */ */ ... nfi • Normal for 2 or more times (Immediately after the V-Blank Process). PER_GetPer (PerGetPer **) &get_per); /* get peripheral data */ get_tin = PER_GET_TIM (); /* get time */ . . . Co if (((get_per[2].data) & PER_DGT_U) == PER_DGT_U_) { /* current pe- ripheral data of connector 3 is UP ? */ . . . GA SE Saturn System Library User's Guide 23 6.0 Data Specifications 6.1 List of Data IntBack Peripheral ID data type Peripheral size data type IntBack Kind Required number of peripherals Function nti Function name PerId al PerSize PerKind PerNum No. 2 3 4 1 System data output data type PerGetSys 5 Peripheral data output data type PerGetPer 6 Device information data type Digital device info data type PerDgtInfo 7 Analog device info data type PerAnlInfo 8 Device Data Type de Pointing device info data type Keyboard device info data type PerPntInfo PerKbdInfo Mega Drive 3-button pad info data type PerM3bpInfo Mega Drive 6-button pad info data type PerM6bpInfo Digital device data type PerDgtData 9 10 11 12 13 nfi Analog device data type Pointing device data type Keyboard device data type Mega Drive 3-button pad data type Mega Drive 6-button pad data type PerAnlData PerPntData PerKbdData PerM3bpData PerM6bpData 14 15 16 17 18 Co GA SE 24 6.2 Data Specifications IntBack command issuance Title Data Specifications Data Peripheral ID data type This data type shows the peripheral ID. Constant name Description ntial Data Name PerId No. 1 PER_ID_NCON Unconnected PER_ID_UNKNOW Peripherals that cannot be processed by SMPC PER_ID_DGT Digital Device PER_ID_ANL PER_ID_PNT PER_ID_KBD PER_ID_M3BP PER_ID_M6BP Analog Device de Pointing Device (Mega Drive mouse) Keyboard Mega Drive 3-button pad Mega Drive 6-button pad Title Data Specifications Data nfi Peripheral size data type This data type shows the peripheral size. Data Name PerSize No. 2 Constant name PER_SIZE_DGT PER_SIZE_ANL PER_SIZE_PNT PER_SIZE_KBD Co Digital Device Analog Device Description Pointing Device (Mega Drive mouse) Keyboard PER_SIZE_M3BP Mega Drive 3-button pad PER_SIZE_M6BP Mega Drive 6-button pad GA SE Saturn System Library User's Guide 25 Title Data Data Name No. Data IntBack kind data type PerKind 3 Specifications This data type shows the IntBack kind. Constant name PER_KD_SYS PER_KD_PER PER_KD_PERTIM Description System data acquisition (except time) Peripheral data acquisition ntial Peripheral data acquisition + time data acquisition Title Data Data Name No. Data Specifications Required number of peripherals data type This data type shows the required number of peripherals. Value 0 ~ 31 Meaning 1P ~ 32P de PerNum 4 Title Data Specifications Data System data output data type nfi Data Name PerGetSys No. 5 PerGetSys *data Co This data type shows the system data output. Access Macro PER_GS_AC (data) PER_GS_SS (data) PER_GS_SM (data) Type Uint8 Uint16 Uint32 Area code Description System status SMPC memory PER_GS_SMPC_STAT (data) Uint8 SMPC status GA SE 26 Shown below are the constants and values that can be used by each access macro. PER_GS_CC (data) bit 7 0 0 PER_GS_AC (data) bit 7 0 0 0 0 CTR1 ACODE ACODE ACODE ACODE nti bit 0 CTR0 al bit 0 0 0 0 0 3 2 1 0 See the hardware manual for areas indicated an area codes. PER_GS_SS (data) Bit Position Constant PER_SS_DOTSEL PER_SS_SYSRES PER_SS_MSHNMI de Acquisition Value DOTSEL signal status SYSRES signal status MSHNMI signal status PER_SS_SNDRES PER_SS_CDRES Description of Acquisition Values Value nfi SNDRES signal status CDRES signal status Meaning 0 1 PER_GS_SM (data) Co OFF ON Areas which are used in common by applications and Boot ROM. Bit Position Constant PER_MSK_LANGU Acquisition Value Language (see below) PER_MSK_SE SE (0: ON, 1: OFF) PER_MSK_STEREO STEREO or MONO (0: STEREO, 1: MONO) GA PER_MSK_HELP Language Constant Constant PER_JAPAN PER_ENGLISH PER_FRANCAIS HELP (0: ON, 1: OFF) Description Japanese English French PER_DEUTSCH German SE PER_ITALIANO PER_ESPNOL Italian Spanish Saturn System Library User's Guide 27 PER_GS_SMPC_STAT (data) Bit Position Constant Acquisition Value nti PER_SS_RESET Reset mask condition 0: reset enable 1: reset disable (default) al PER_SS_SETTIME Time set condition 0: time is not set after SMPC cold reset 1: time is set after SMPC cold reset Title Data Data Name No. Data Peripheral data output data type PerGetPer 6 Specifications This data type shows peripheral data output. • Device Information Data Type Title Data de Data Name No. Data Specifications Digital device information data type This data type shows digital device information. typedef struct { /* nfi digital device PerDgtInfo 7 */ Title Data PerDgtData PerDgtData PerId } PerDgtInfo; Specifications Data data; push; id; Co /* /* /* current peripheral data peripheral ID Data Name No. */ previously not pressed currently pressed button */ Analog device information data type PerAnlInfo 8 */ This data type shows analog device information. PerAnlData PerAnlData PerId GA typedef struct } PerAnlInfo; { data; push; id; /* /* /* /* analog device current peripheral data */ */ previously not pressed currently pressed button */ peripheral ID */ SE 28 Title Data Data Name No. Data Pointing device information data type PerPntInfo 9 Specifications This data type shows pointing device information. typedef struct PerPntData PerPntData PerId } PerPntInfo; { data; push; id; /* /* /* /* pointing device peripheral ID ntial current peripheral data */ */ previously not pressed currently pressed button */ */ Title Data Data Name No. Data Keyboard device information data type PerKbdInfo 10 Specifications This data type shows keyboard device information. typedef struct PerKbdData PerKbdData PerId } PerKbdInfo; { data; push; id; /* /* /* /* de keyboard device current peripheral data */ */ previously not pressed currently pressed button */ peripheral ID */ Title Data Specifications Data nfi Mega Drive 3-button pad information data type This data type shows Mega Drive 3-button pad information. Data Name PerM3bpInfo No. 11 Title typedef struct PerM3bpData PerM3bpData PerId } PerM3bpInfo; Data Co { data; push; id; /* /* /* /* Mega Drive 3-button pad current peripheral data */ previously not pressed currently pressed button */ peripheral ID Data Name No. */ */ Data Mega Drive 6-button pad information data type PerM6bpInfo 12 Specifications GA This data type shows Mega Drive 6-button pad information. typedef struct PerM6bpData PerM6bpData PerId } PerM6bpInfo; { data; push; id; /* /* /* /* Mega Drive 6-button pad current peripheral data */ */ previously not pressed currently pressed button */ peripheral ID */ SE Saturn System Library User's Guide 29 • Device Data Type The meaning of the device data bit acquisition value is explained below. nti Description of Acquisition Values Value Meaning 0 Button is pressed al 1 Button is not pressed Title Data Data Name No. Data Digital device data type PerDgtData 13 Specifications This data type shows the digital device. typedef Uint16 Bit Position Constant PER_DGT_U PER_DGT_D UP DOWN PerDgtData; Acquisition Value de /* digital device data type */ PER_DGT_R PER_DGT_L PER_DGT_A PER_DGT_B PER_DGT_C RIGHT LEFT A B C nfi PER_DGT_S PER_DGT_X PER_DGT_Y PER_DGT_Z PER_DGT_TR PER_DGT_TL START X Y Z Co TRG-RIGHT (upper right of the device) TRG-LEFT (upper left of the device) Title Data Data Name No. Data Specifications GA Analog device data type This data type shows the analog device. typedef struct PerDgtData Sint16 { dgt; x; PerAnlData /* analog device data type /* digital device data type /* X axis absolute value (0 ~ 255) 14 */ */ */ Sint16 y; /* Y axis absolute value (0 ~ 255) */ SE Sint16 z; /* Z axis absolute value (0 ~ 255) */ } PerAnlData; 30 Title Data Data Name No. Data Pointing device data type PerPntData 15 nti Specifications This data type shows the pointing device. typedef struct PerPntData Sint16 Uint16 Sint16 } PerPntData; { dgt; data; x; y; /* pointing device data type /* digital device data type /* data al /* amount of X axis movement (-128 ~ 127) /* amount of Y axis movement (-128 ~ 127) Shown below are constants and values that can be used by each member. */ */ */ */ */ Data Bit Position Constant PER_PNT_R PER_PNT_L PER_PNT_MID PER_PNT_CNT RIGHT LEFT MIDDLE CENTER de Acquired value PER_PNT_X0 PER_PNT_Y0 Title Data Data nfi X axis overflow (0: overflows, 1: does not overflow) Y axis overflow (0: overflows, 1: does not overflow) Keyboard device data type Data Name PerKbdData No. 16 Specifications This data type shows the keyboard device. typedef struct PerDgtInfo Uint8 Uint8 Co { dgt; skey; key; /* keyboard device data type /* digital device data type /* special key /* key */ */ */ */ } PerKbdData; Shown below are constants and values that can be used by each member. GA skey Bit Position Constant PER_KBD_CL PER_KBD_NL PER_KBD_SL Caps Lock Num Lock Scroll Lock Acquired value PER_KBD_MK Make (0: key pressed, 1: key not pressed) SE PER_KBD_BR Break (0: key released, 1: key not released) Saturn System Library User's Guide 31 Title Data Data Name No. Data Mega Drive 3-button pad data type PerM3bpData 17 Specifications This data type shows the Mega Drive 3-button pad. typedef Uint8 PerM3bpData; nti /* Mega Drive 3-button pad data type al PER_M3BP_U ~ PER_M3BP_S is the same as PER_DGT_U ~ PER_DGT_S. PER_DGT_X ~ PER_DGT_TL is the condition when the button is not pressed. */ Bit Position Constant Acquired Value PER_M3BP_U UP PER_M3BP_D DOWN PER_M3BP_R PER_M3BP_L PER_M3BP_A PER_M3BP_B PER_M3BP_C PER_M3BP_S RIGHT LEFT A B C START de Title Data Specifications Data Mega Drive 6-button pad data type nfi Data Name PerM6bpData No. 18 typedef Uint16 Co This data type shows the Mega Drive 6-button pad. PerM6bpData; /* Mega Drive 6-button pad data type PER_M6BP_U ~ PER_M6BP_MD is the same as PER_DGT_U ~ PER_DGT_TR. PER_DGT_TL is the condition when the button is not pressed. Bit Position Constant Acquisition Value */ PER_M6BP_U UP PER_M6BP_D DOWN PER_M6BP_R PER_M6BP_L PER_M6BP_A PER_M6BP_B PER_M6BP_C PER_M6BP_S GA RIGHT LEFT A B C START PER_M6BP_X X SE PER_M6BP_Y PER_M6BP_Z PER_M6BP_MD Y Z MODE (upper right of device) 32 7.0 Function Specifications 7.1 List of Functions Non-IntBack Command Issue Sound OFF Function Master SH2 ON Slave SH2 ON Slave SH2 OFF Sound ON nti Function Name PER_SMPC_MSH_ON al PER_SMPC_SSH_ON PER_SMPC_SSH_OFF PER_SMPC_SND_ON PER_SMPC_SND_OFF No. 1 2 3 4 5 CD ON PER_SMPC_CD_ON 6 CD OFF PER_SMPC_CD_OFF 7 Reset entire system PER_SMPC_SYS_RES 8 NMI request de Hot reset enable Hot reset disable SMPC memory set Time set PER_SMPC_NMI_REQ PER_SMPC_RES_ENA PER_SMPC_RES_DIS PER_SMPC_SET_SM PER_SMPC_SET_TIM 9 10 11 12 13 IntBack Other Command Issue Other nfi IntBack Initialization Peripheral data acquisition Time acquisition System data acquisition Hot reset acquisition PER_Init PER_GetPer PER_GET_TIM PER_GET_SYS PER_GET_HOT_RES 14 15 16 17 18 Non-IntBack Co 7.2 Function Specifications Title Function Function Master SH2 ON ~ hot reset disable Function Name No. PER_SMPC_MSK_ON ~ 1 ~ 11 Specifications PER_SMPC_RES_DIS GA Format: void PER_SMPC_XXX (void) Input: None Output: None Function Value: None Function: As per the list of function specifications. See the SMPC hardware manual for details. SE Saturn System Library User's Guide 33 Title Function Function Name No. Function Sets SMPC memory PER_SMPC_SET_SM 12 Specifications Format: Input: Output: Function Value: Function: void PER_SMPC_SET_SM (Uint32 input_dt) input_dt : SMPC memory nti See System data output data type for the meaning of each bit value. None None Sets the SMPC memory. Because the SMPC memory is an area that al is used in common by applications and the Boot ROM, the format must be observed. Title Function Function Name No. Function Specifications Format: Input: Input Format Sets time void PER_SMPC_SET_TIM (Uint8 input_dt: time de PER_SMPC_SET_TIM * input_dt) 13 *(input_dt) *(input_dt + 1) *(input_dt + 2) *(input_dt + 3) bit7 second (10 digit) minute (10 digit) nfi bit4 hour (10 digit) day (10 digit) bit3 second (1 digit) minute(1 digit) hour (1 digit) day (1 digit) bit0 *(input_dt + 4) *(input_dt + 5) *(input_dt + 6) Co day of week (0 ~ 6) year (10 digit) year (1000 digit) month (1H ~ CH) year (1digit) year (100 digit) • Day data: Sunday is 0, Monday is 1, Tuesday is 2 . . . • Month data is hexadecimal data. Output: None Function Value: None GA Function: Sets the time. SE 34 IntBack Title Function Function Name No. Function Initializes IntBack PER_Init 14 Specifications Format: Input: nti Uint32 PER_Init (PerKind kind, PerNum num, PerId id, PerSize size, Uint32 work[n], Uint8 v_blank) kind num id size : IntBack type al : Required number of peripherals : Peripheral ID : Peripheral size work : Work area (Use for getting peripheral data. Must be declared by a global variable.) v_blank : Number of V-Blank skip • Method for calculating the work area n = (num x data A)/4 + data B round up to nearest digit de Peripheral nfi Data A and data B change depending on the peripheral. Digital device Analog device Pointing device Data A 12 36 36 Data B 1 2 2 Output: Function Value: Co Keyboard device Mega Drive 3-button pad Mega Drive 6-button pad none execution condition 20 6 12 1 1 1 Constant Description GA PER_INT_ERR Could not issue the IntBack command PER_INT_OK Could issue the IntBack command Function: Initializes IntBack and issues the IntBack command. Execution rules must be obvserved. Set Null or 0 to unneeded parameters. Execute at least 1 time before executing PER_GetPer (), PER_GetTim(), PER_GetSys(). Remarks: Generally, this should be executed immediately after the V-Blank process. Other interrupts are prohibited during SMPC interrupts. SE Note: DO NOT perform this function within the interrupt process. Be sure to perform via the main process. Saturn System Library User's Guide 35 Title Function Function Name No. Function Peripheral data acquisition PER_GetPer 15 Specifications Format: Input: Output: Function Value: Uint32 PER_GetPer (PerGetPer **output_dt) none nti output_dt: peripheral output address (Null = cannot get) Execution conditions. Constant al Description PER_INT_ERR Could not issue the IntBack command. PER_INT_OK Could not issue the IntBack command. Function Value: Issues the IntBack command and gets peripheral data. Execution Remarks: specified. de rules must be observed. Before this function is executed, specify “pe- ripheral data get” to PER_Init() and execute at least once. Null is output to the peripheral data address when peripheral data get is not Generally, this should be executed immediately after the V-Blank process. Other interrupts are prohibited during SMPC interrupt. Title Function Specifications Format: Input: Function Gets time Uint8 none nfi *PER_GET_TIM (void) Function Name PER_GET_TIM No. 16 Output: Function Value: Function: Title Function none Co Time data address Gets time data. Before this function is executed, instructs peripheral data get and time get to PER_Init() and execute at least once. Function Name No. Function Gets system data PER_GET_SYS 17 Specifications GA Format: PerGetSys *PER_GET_SYS (void) Input: none Output: none Function Value: System data address (NULL = could not get) Function: Gets system data. Instructs system data get to PER_Init () before this function is executed and execute at least once. Execute this function about 300 µs after executing PER_Init. SE 36 Other Title Function Function Name No. nti Function Gets hot reset PER_GET_HOT_RES 18 Specifications Format: Uint8 PER_GET_HOT_RES (void) Input: none Output: Function Value: none Hot reset condition address Constant PER_HOT_RES_ON PER_HOT_RES_OFF al Hot reset ON Hot reset OFF Description Function: de Gets the hot reset condition. This function can be executed at any time. Update is performed by PER_GetPer(). nfi Co GA SE Saturn System Library User's Guide 37 (This page is blank in the original Japanese version.) ntial de nfi Co GA SE 38 Backup Library User’s Manual 1.0 Guide 1.1 Purpose ntial In addition to the builit-in memory in this game machine, several types of storage devices are being planned for storing information during a game. This library provides functions for reading, writing and searching these backup storage devices. 1.2 Explanation 1.2.1 Introduction de Always use this library when accessing storage devices for backup. 1.2.2 How to Use This Library can be used. nfi The library itself is compressed and stored in the boot ROM. The application pro- grammer expands the library and uses it. Expansion is performed by securing a program expansion area and executing BPU_Init(). Once this is done, each function 1.2.3 Storage Capacity Co The object of this library is to facilitate access of devices to be supported in the future through a common interface, and therefore the capacity of the storage devices to be developed in the future is not known. Also, depending on the device, it will be divided up into multiple areas. Each one of these unit areas is called a partition (the capacity of each partition may be different). When storing data, execute BUP_SelPart() and BUP_Stat() and confirm the capacity before writing. The built-in backup memory is 32 Kbyte. GA 1.2.4 Date Setting In order to preserve the uniqueness of this library, it does not have a function for acquiring the date and time. Set the date and time data by having the application use BPU_SetDate(). 1.2.5 Precautions This library will destroy data if writing is interrupted. Before executing BUP_Init(), BUP_Format(), BUP_Write() and BUP_Delete, disable the reset button by using SE PER_SMPC_RES_DIS() in the system library. Saturn System Library User's Guide 39 1.3 Program Example An example of a program written in C is shown below. #include “sega_per.h” #define BUP_START_ADDR #include “sega_bup.h” Unit32 main() [ 0x60????0 BackUpRamWork[2048]; BupConfig conf[3] nti /*sets write address for library al */ BupStat sttb; BupDir writetb; BupDate datatb; Unit8 *time; PER_SMPC_RES_DIS(); de /*disables reset button BUP_Init(BUP_START_ADDR, BackUpRamWork, conf); if(BUP_Stat(0, &sttb)==BUP_UNFORMAT) { } BUP_Format(0); PER_SMPC_RES_ENA(); /*enables reset button */ */ BUP_Stat(0, &sttb); if(sttb.freeblock > 0) { nfi strcpy((char *)writetb.filename, “FILE_NAME01”); STRCPY((char *)writetb.comment, “test”); writetb.language = BUP_JAPANESE; time = PER_GET_TIM(); /*get date and time datetb.year = (Uint8 )( (Uint16 )(time[6]>>4) * 1000 + (Uint16 )(time[6] & 0x0F) * 100 */ datetb.day Co + (Uint16 )(time[5]>>4) * 10 + (Uint16 )(time[5] & 0x0F) - 1980); datetb.month = time[4] & 0x0F; = (time[3]>>4)*10 + (time[3] & 0x0F); datetb.time = (time[2]>>4)*10 + (time[2] & 0x0F); datetb.min writetb.date = (time[1]>>4)*10 + (time[1] & 0x0F); = BUP_SetDate(&datetb); writetb.datasize = 10; PER_SMPC_RES_DIS(); /*disable reset button */ BUP_Write(0, &writetb, “Dummy Data”); PER_SMPC_RES_ENA(); /*enable reset button */ GA SE 40 2.0 Reference 2.1 Data List Title Data specification Data Storage device connection information typedef struct BupConfig { Uint16 unit_id; Uint16 partition; } BupConfig; ntial /*unit ID Data Name BupConfig /*number of partitions No. */ */ *When unit_id is "0", it indicates non-connection. Type of device unit_id partition Built-in memory 1 1 Title Data specification External cartridge Function Status information typedef struct BupStat { de 2 1 Function Name BupStat No. nfi Uint32 totalsize; Uint32 totalblock; Uint32 blocksize; Uint32 freesize; Uint32 freeblock; Uint32 datanum; } BupStat; /*total capacity (bytes) /*number of blocks /*size of one block (bytes) /*open space /*number of open blocks /*number of items that can be written */ */ */ */ */ */ Title Co The value for the size specified by BUP_Stat() for datasize is stored in datanum. Data specification Function Date and time typedef struct BupStat { Uint8 year; Function Name BupDate /*year (1980 subtracted from year No. */ Uint8 month; /*month (1-12) */ Uint8 day; /*day (1-31) */ Uint8 time; /*hour (0-23) */ GA Uint8 min; Uint8 week; } BupDate; /*minute (0-59) /*day of week (sunday 0- saturday 6) */ */ SE Saturn System Library User's Guide 41 Title Function Function Name No. Data specification Directory information BupDir typedef struct BupStat { Uint8 Uint8 Uint8 filename[12]; comment[11]; language; /*file name /*total 12 bytes ASCII 11 characters + NUL /*comment ntial /*total 11 bytes ASCII 10 characters + NUL /*language of comment /* Japanese /* English BUP_JAPANESE BUP_ENGLISH */ */ */ */ */ */ */ /* French BUP_FRACAIS */ /* German BUP_DEUTSCH */ /* Spanish BUP_ESPAN0L */ /* Italian BUP_ITALIANO */ 2.2 Function List Uint32 Uint32 Uint16 } BupDir; date; datasize; blocksize; de /*date and time data /*data size (unit: byte) /*data size (unit: block) */ */ */ Get status Function Backup library Initialize backup library Select partition Execute format Write data nfi Function Name BUP_Init BUP_SelPart BUP_Format BUP_Stat BUP_Write No. 1 2 3 4 5 Read data Delete data Co Get directory information Verify data Open date and time data Compress data and time data BUP_Read BUP_Delete BUP_Dir BUP_Verify BUP_GetDate BUP_SetDate 6 7 8 9 10 11 GA SE 42 2.3 Data Flow HOST Write Read ntial Storage device for backup 2.4 Function Specifications Title Function Function Name No. Function specification Initializes backup library BUP_Init 1 Format Input void de BUP_Init(Uint32 *libaddr,Uint32 *workbuff,BupConfig conf[3]) libaddr : specifies address to which library is loaded. The size of the library is 16 Kbytes. workbuff : point for library work area A work area size of 8192 bytes is required. Long word access may also be performed, so be sure to secure Output Function conf nfi with Uint32. : Gets information on the connected storage device. Loads the backup library to the specified memory area and prepares it for use. Gets information on the connected storage device. The following device numbers correspond to three tables. Notes Example Co Device No. 0 1 2 Built-in memory cartridge Device Type Memory cartridge or parallel interface Serial interface Always prepare three storage device connection information tables. #define BUP_START_ADDR 0x6?????? #include”sega_bup.h” Uint32 workmemory[2048] GA voidsample() { } BupConfig conf[3] BUP_Init(BUP_START_ADDR, workmemory, conf); ............... SE Saturn System Library User's Guide 43 Title Function Function Name No. Function specification Partition selection BUP_SelPart 2 Format Input Sint32 BUP_SelPart(Uint32 device,Uint16 num) device : device number num 0: built-in memory 1: memory cartridge or parallel interface 2: serial interface : partition number 0 - (number of partitions - 1) ntial Output none Function value 0 : success other : failure Title Function Function specification Format de Selects a partition. In the initial condition, partition 0 is selected. Function Executes format Sint32 BUP_Format(Uint32 device) Function Name BUP_Format No. 3 Input Output Function value device : device number none 0 nfi 0: built-in memory 1: memory cartridge or parallel interface 2: serial interface : success Function other Co BUP_WRITE_PROTECT : write protected : failure Initializes the backup storage device. Formats only the current partition in a partitioned backup storage device. GA SE 44 Title Function Function Name No. Function specification Gets status BUP_Stat 4 Format Input Sint32 *stat) nti BUP_Stat(Uint32 device,Uint32 datasize,BupStat device : device number 0: built-in memory al 1: memory cartridge or parallel interface 2: serial interface datasize : specify size of data to be written in byte units Output stat : status information Function value returns device status 0 : success BUP_NON : not connected Function Title Function specification de BUP_UNFORMAT : not formatted Gets status information. Function Writes data Function Name BUP_Write No. 5 Format Input Sint32 owsw) nfi BUP_Write(Uint32 device, BupDir *dir,Uint8 *data,Uint8 device : device number 0: built-in memory 1: memory cartridge or parallel interface Output Co 2: serial interface dir : file control information (input other than dir.blocksize) data : pointer for write data owsw: overwrite check mode none ON: does not write if file of same name exists OFF: writes on file if file of same name exists Function value 0 : success BUP_NON : not connected GA Function BUP_UNFORMAT BUP_WRITE_PROTECT BUP_FOUND Other : not formatted : write protect exists : file of same name exists : failure Writes data to the backup storage device. SE Saturn System Library User's Guide 45 Title Function Function Name No. Function specification Loads data BUP_Read 6 Format Input Sint32 *data) nti BUP_Read(Uint32 device, Uint8 *fname, Uint8 device : device number 0: built-in memory 1: memory cartridge or parallel interface 2: serial interface al fname : file name specification (11 characters are required in ASCII) Output data : pointer for load destination buffer Function value 0 : success BUP_NON : not connected Title Function BUP_UNFORMAT de : not formatted BUP_NOT_FOUND : file not found BUP_BROKEN Other : file is damaged : failure Loads data from the backup storage device. Function Function Name No. Function specification Format Input Deletes data Sint32 nfi BUP_Delete BUP_Delete(Uint32 device, Uint8 *fname) device : device number 0: built-in memory 1: memory cartridge or parallel interface 7 2: serial interface Output Function value none Co fname : file name (11 characters is required in ASCII) 0 BUP_NON BUP_UNFORMAT BUP_NOT_FOUND : success : not connected : not formatted : file not found BUP_WRITE_PROTECT : write protect exists Other : failure GA Function Deletes data on the backup storage device. SE 46 Title Function Function Name No. Function specification Gets directory information BUP_Dir 8 Format Input Sint32 nti BUP_Dir(Uint32 device,Uint8 *fname,Uint16 dirsize, BupDir *dir) device : device number 0: built-in memory al 1: memory cartridge or parallel interface 2: serial interface fname : file name specification (within 11 ASCII characters) dirsize : specifies the number of directory info secured Output dir : stores directory information Function value number of directory information hits Function The file name is done by searching forward, and the directory infor- mation is stored in a table. The number of directories hit by the search de is returned as the function value. If negative, it indicates that the table is too small, and the number of hits can be confirmed by inverting the sign (if the result is 11 when the tbsize is set to 10 and a search is performed, -11 is returned). Title Function specification Format Input Function nfi Verify data Sint32 *data) device Function Name BUP_Verify BUP_Verify(Uint32 device, Uint8 *filename,Uint8 : device number No. 9 Output Function value Co filename data none 0 0: built-in memory 1: memory cartridge or parallel interface 2: serial interface : file name (11 characters are required in ASCII) : pointer for data verification : success BUP_NON : not connected BUP_UNFORMAT : not formatted GA BUP_NO_MATCH : data do not agree BUP_NOT_FOUND : file not found BUP_BROKEN : file is damaged Function Verifies data written to the backup file. SE Saturn System Library User's Guide 47 Title Function Function Name No. Function specification Expands data and time data BUP_GetDate 10 Format Input Output Function value Function void nti BUP_GetDate(Uint32 pdate,BupDate *date) pdate : data and time data of directory information date : date and time table none none al Expands the date and time data in the directory information table. Title Function Function Name No. Function specification Compress date and time data BUP_SetDate 11 Format Input Output Function value Function Uint32 de BUP_SetDate(BupDate *date) date : date and time table none Data in date and time data form in the directory information table. Compresses the date and time data in the directory information table. nfi Co GA SE 48