When using this document, keep the following in mind:ntialGeneral Notice

1. This document is confidential. By accepting this document you acknowledge that you are boundby the terms set forth in the non-disclosure and confidentiality agreement signed separately and /inthe possession of SEGA. If you have not signed such a non-disclosure agreement, please contact
SEGA immediately and return this document to SEGA.

de2. This document may include technical inaccuracies or typographical errors. Changes are periodically made to the information herein; these changes will be incorporated in new versions of the
document. SEGA may make improvements and/or changes in the product(s) and/or the
program(s) described in this document at any time.

nfi

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 technicalinformation about SEGA products must be made to your authorized SEGA Technical Services
representative.

Co

4. No license is granted by implication or otherwise under any patents, copyrights, trademarks, orother intellectual property rights of SEGA Enterprises, Ltd., SEGA of America, Inc., or any third
party.
5. Software, circuitry, and other examples described herein are meant merely to indicate the characteristics 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
describe herein.

GA

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 product/program in this document is not intended to state or simply that you can use only SEGA’slicensed 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.

SE

NOTE: A reader's comment/correction form is provided with thisdocument. Please address comments to :(6/27/95- 002)

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.

SE

GA

Co

nfi

de

nti
al

TM

SATURN
System Library
User's Guidever. 1.0
Doc. # ST-162-R1-092994© 1994-95 SEGA. All Rights Reserved.

nti
al

READER CORRECTION/COMMENT SHEETKeep us updated!
If you should come across any incorrect or outdated information while reading through the attacheddocument, or come up with any questions or comments, please let us know so that we can make therequired 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:

Phone

de

Your Name
Document number

ST-162-R1-092994

Document nameSaturn System Library User's Guide, ver. 1.0

Date

Corrections:
Correction

nfi

pg. #

GA

Co

Chpt.

SE

Questions/comments:

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

nti
al

REFERENCES

KenKyusha New Japanese-English Dictionary
1974 Edition

2.

Nelson’s Japanese-English Character Dictionary
2nd revised version

3.

Microsoft Computer Dictionary

4.

Japanese-English Computer Terms Dictionary
Nichigai Associates
4th version

SE

GA

Co

nfi

1.

de

In translating/creating this document, certain technical words and/or phrases were interpretedwith the assistance of the technical literature listed below.

nti
al

Table of Contents
SYSTEM PROGRAM USER’S MANUAL .................................................... 1
1.0

GUIDE ............................................................................................... 1
1.1 Explanation .............................................................................. 1

2.0

REFERENCE .................................................................................... 7
2.1 List of Functions ...................................................................... 7
2.2 Function Specifications ............................................................ 8deSMPC I/F USER’S MANUAL .................................................................... 15

GUIDE ............................................................................................. 15

2.0

FEATURES ..................................................................................... 15

3.0

OVERVIEW ..................................................................................... 16
3.1 Function Overview ................................................................. 16
3.2 Process Overview .................................................................. 16

4.0

DETAILS ......................................................................................... 17
4.1 Functions ............................................................................... 17
4.2 Process ................................................................................. 18
4.3 Peripheral Control .................................................................. 22

5.0

CALLING SEQUENCE .................................................................... 23

6.0

DATA SPECIFICATIONS................................................................. 24
6.1 List of Data ............................................................................ 24
6.2 Data Specifications ................................................................ 25

7.0

FUNCTION SPECIFICATIONS ....................................................... 33
7.1 List of Functions .................................................................... 33
7.2 Function Specifications .......................................................... 33

GA

Co

nfi

1.0

BACKUP LIBRARY USER’S MANUAL ..................................................... 39
1.0 Guide .............................................................................................. 39
1.1 Purpose ................................................................................. 39
1.2 Explanation ............................................................................ 39
1.3 Program Example .................................................................. 40

Reference........................................................................................ 41
2.1 Data List ................................................................................ 41
2.2 Function List .......................................................................... 42
2.3 Data Flow .............................................................................. 43
2.4 Function Specification ........................................................... 43

SE

2.0

1.0

nti
al

System Program User’s Manual
Guide

1.1 Explanation

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 address.

deThe slave SH2 interrupt vector table is the work RAM lead + 400H, and the slave
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. Dummyroutines that do nothing are set in the vector table. (With the exception of invalid
commands and address errors, these are infinite loops.)

nfi

The FRT input capture interrupt is assigned for use in master and slave communications, and its initial priority is 15 (highest priority). In the table below, the priority of
all interrupts, except for the FRT input capture interrupt, is set at 0 and interrupt isunauthorized.

Co

In changing the priority of the built-in module interrupts, the content of the interrupt control register must change in response to the needs of the application.

SE

GA

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
* 64H FRT input capture
65H FRT compare match
66H FRT overflow
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* for slave > master passing

Saturn System Library User's Guide

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
65H FRT compare match
66H FRT overflow
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* for master > slave passing* * IRL2, IRL6 level interrupts

1

nti
al

This operation routine should be used to register the interrupt process routine to theinterrupt vector and to reference the address of the current process routine. Furthermore, a SCU interrupt routine (the master SCU interrupt) that implements the interrupt 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.

deThe 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.
SCU Interrupt Mask Set, Reference, and Change Operations

nfi

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 aservice routine, which preserves and updates in consistency with the actual SCU
interrupt mask register, is provided.

Simple Semaphore Operation

Co

When this routine is used, setting and changing the SCU interrupt mask must always 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.

GA

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 semaphore 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 andshows that it is free.
In a process that requires resources to be secured over a comparatively long periodof time, the semaphore operation and reference procedure should be determined sothat those resources are not accessed arbitrarily by an interrupt process during that
period of time.

SE

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
the process that acquired semaphore is completed. All semaphore memory iscleared when reset.

2CPU ClockHorizontal Resolution

26 MHz
320/640

←→
←→

nti
al

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 apartial hardware reset.
28 MHz352/704

Unaffected Devices
Master SH * note
SDRAM
CD
SIMM (development devices only)deReset Devices
OFF or non guaranteed Devices
SCU
Slave SH (OFF)VDP1DRAM (previous content destroyed)
VDP2
SCSP (OFF)SCSI/SCC (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.

Reinitializing process after reset:

SCU:

nfi

NMI goes to its existed status after the process; for example, the DMAC control goes to interrupt status by NMI. See the SH manual. If necessary, perform the reopen process.

Reinitializes the bus, interrupt mask, etc. However, the value of
SYS_GETSCUIM is used for the interrupt mask value.

VDP2:

The TV mode must be set comparatively fast. Because the 320/640 mode isused after the device itself is reset, especially when the system clock ischanged to the 352/704 mode, the synchronous signal shifts in the TV andturbulence occurs on the screen.

VDP1, 2, SCSP:All previous settings are invalid. Must be reset.

Hot reset must be enabled.

GA

SMPC:

Co

Postprocesses required with applications:SE

The clock change process time is about 110 ms, which includes the reset time of thedevice.

Saturn System Library User's Guide

3

Note:ntial

SCU Interrupt Routine Priority Change
The Boot ROM has an interrupt priority control table used for the SCU interrupt
process service, making rewrite possible.
This is a risky service. The system may hang up if priority relationship inconsistencies
exist in the table contents.

With this, the interrupt process (items using SYS_SETUINT) can be optimized in theapplication.
To use this, prepare the same structural data for the application as the table, and call
SYS_CHGUIPR.

SCU interrupt mask insignificant word value

The value set to SR at the beginningof the interrupt process

ORed with the current mask set value
and written to the SCU interrupt mask
register at the beginning of the interrupt
process.

nfi

SH2 SR insignificant word value

deTables are of 32 long words. 1 long word has the following contents.

Co

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
correspond to vectors 4EH and 4FH are included.)
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:

0x0070FE00,

SE

} ;

4

/* VBI
SR=15/* VBO
SR=14/* HBI
SR=13.
.
/* External 15

GA

Uint32 PRITab[32] = {0x00F0FFFF,
0x00E0FFFE,
0x00D0FFFF,

All prohibited (highest priority) */Only VBI is allowed*/
VBI and VBO are allowed
*/

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 becauseof the common use and 1 bit
mask, it is set to 7.
*/

nti
al

The creation example shown is one in which the SR value is always set to 0, andpriorities are described only using SCU mask values (priority relationship). Here,SH always receives an interrupt and only the SCU mask controls authorization andprohibition.
Uint32 PRITab[32] = {0x0000FFF9,/* during VBI process HBI and VBO authorization*/
0x0000FFFB,/* during VBO process only HBI authorization*/
0x00D0FFFC,/* during HBI process all prohibited (highest priority)*/.
.
0x00000000,/* during external 15 process, all authorized (lowest priority) */} ;de

The inverse of the example above is prohibiting mask interrupt at SR value levels withoutchanging the SCU mask value. (0 or 15 only are possible.)

Note:

nfi

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 andprohibition.
When the SCU factor interrupt is allowed and interrupt occurs, it is okay if the SH SR mask ishigher than the interrupt unique level (value decided by SCU hardware) and if interrupt cannever be refused by SH. (However, one exception is that all of SR mask 15 can be prohibited.)

CD Multiplayer Startup Execution

Co

This is a service that activates and executes the CD multiplayer when an applicationends. When this service is called, the CD multiplayer screen is displayed exactly thesame 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

SE

GA

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 besaved with the reset button (NMI).

Saturn System Library User's Guide

5

SE

GA

Co

nfi

de

nti
al

(This page is blank in the original Japanese document.)

6Reference

2.1 List of Functions
Function

nti
al

2.0

Function Name

No.

Registers process routine to the interrupt vector

SYS_SETSINT

1.1

Registers function to SCU interrupt routine

SYS_SETUINT

1.2

SYS_GETSINT

1.3

SYS_GETUINT

1.4

Interrupt Process Routine Registration / Reference

Gets registration contents of interrupt vector
Gets registration contents of SCU interrupt
routineSets SCU interrupt maskde

SCU Interrupt Mask Set, Reference, and Change Operations

SYS_SETSCUIM

2.1

SYS_CHGSCUIM

2.2

SYS_GETSCUIM

2.3

SYS_TASSEM

3.1

SYS_CLRSEM

3.2

Switches system clock

SYS_CHGSYSCK

4.1

References system clock value

SYS_GETSYSCK

4.2

SYS_CHGUIPR

5.1

SYS_EXECDMP

6.1

SYS_PCLRMEM

7.1

Changes SCU interrupt mask
References SCU interrupt mask
Simple Semaphore Operation
Clears semaphore
System Clock Switchingnfi

Gets semaphoreCo

SCU Interrupt Routine Priority Change

Changes SCU interrupt routine priority
CD Multi-player Startup Execution

Executes startup of CD multi-player
Power On Clear Memory Operation

SE

GA

Operates power-on clear memory

Saturn System Library User's Guide

7

nti
al

2.2 Function Specifications
Title

Function

Function Name

No.

Function
Specifications

To the interrupt vector; registers interrupt processroutineSYS_SETSINT

1.1

Format:Input:

void SYS_SETSINT (Uint 32 Num, void*

Remarks:denfi

Output:Function Value:
Function:

Function

Function
Specifications

To SCU interrupt routine; registers processfunctionNo.

SYS_SETUINT

1.2

Hdr);

GA

Num : vector number (SCU vector number)
Hdr : function routine address (dummy routine when 0)
None
None
Hdr must be a function by SHC. If the routine is created by theassembler, it must follow the SHC register save protocol.
Num is limited to SCU interrupt vectors (40H..4DH,50H..5FH).
A dummy routine is registered when Hdr is 0. There is no range
check. Values beyond restricted range must not be specified.
When a routine is registered to a vector by SYS_SETSINT, the SCU
interrupt process routine of that vector becomes ineffective andthe registration function is not called. Results are not guaranteed
when this routine is called via SH2 slave.

SE
8

Function Name

void SYS_SETUINT (Uint 32 Num, void*

Output:Function Value:
Function:

Remarks:

Co

Title

Format:Input:

Hdr);

Num : vector number (0..7FH)
Hdr : interrupt process routine address (dummy routine when 0,
or that interrupt process routine when Num is the SCU
interrupt vector)
None
None
Hdr must be a process routine that ends by register save, return, andRTE 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.
This routine can be used with both master and slave SH2
and is registered to vector addresses based on each VBR.

Function

Function Name

No.

Function
Specifications

Gets registration contents of interrupt vector

SYS_GETSINT

1.3

Remarks:

void (*) ()SYS_GETSINT (Uint 32 Num) ;Num : vector number (0..7FH)
None
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 mustnot be specified.
This routine can be used with both master and slave SH2 and refers to
the vector addresses based on each VBR.

deFormat:Input:
Output:Function Value:
Function:

nti
al

Title

Title

Function

Function
Specifications

Gets registration contents of SCU interrupt
routine

SYS_GETUINT

1.4

SYS_GETUINT (Uint 32 Num) ;nfi

Remarks:

void (*) ()No.

Num : vector number (SCU vector number)
None
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.

Co

Format:Input:
Output:Function Value:
Function:

Function Name

Title

Function

Function Name

No.

Function
Specifications

Sets SCU interrupt mask

SYS_SETSCUIM

2.1

void

SYS_SETSCUIM (Uint 32

MaskPat) ;MaskPat : SCU interrupt mask value
None
None
Writes the MaskPat value to mask save memory and to the SCU
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 interrupt 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(SCU specifications). This possibility should either be avoided or theusage should occur under conditions where there is no related knowledge thereof. Results cannot be guaranteed when this routine iscalled via slave SH2.

GA

Format:Input:
Output:Function Value:
Function:SE

Remarks:

Saturn System Library User's Guide

9

Function

Function Name

No.

Function
Specifications

Changes SCU interrupt mask

SYS_CHGSCUIM

2.2

Format:Input:

void SYS_CHGSCUIM (Uint 32

References SCU interrupt mask value

Uint 32

Function NameNo.

SYS_GETSCUIM

2.3

None
None
Mask save memory value
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
set in the SCU interrupt mask register.
During the SCU interrupt process, the change is made to the valuethat is set when the application uses SYS_SETSCUIM () and
SYS_CHGSCUIM () where the change is made to the logical sumof 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
undefined during the SCU interrupt process. During this procedure,a process that relies on referenced values should not be performed.

SE
10

OrMask) ;SYS_GETSCUIM ;GA

Format:Input:
Output:Function Value:
Function:

Remarks:nfi

FunctionCo

Remarks:

Function
Specifications

AndMask, Uint32

AndMask: Mask value used for authorizing
OrMask: Mask value used for denying
None
None
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 OrMask 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 iscleared 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 theprocess (SCU specifications). This possibility should either be
avoided or the usage should occur under conditions where there is no
related knowledge thereof. Results cannot be guaranteed when thisroutine is called via slave SH2.

deOutput:Function Value:
Function:

Title

nti
al

Title

Function

Function Name

No.

Gets semaphore

SYS_TASSEM

3.1

Format:Input:
Output:Function Value:
Function:

Uint 32

SYS_TASSEM (Uint 32

Num) ;

Num : semaphore number (0 ~ FFH)
None
Result (1: acquired, 0: already acquiring another)
TAS command to memory (1 byte) linked to Num number is executedand the results are returned to function values. There is no range
check. Values beyond the restricted range must not be specified. Thisroutine can be used with both master and slave SH2.

Title

Function

Function
Specifications

Clears semaphore

void

SYS_CLRSEM (Uint 32

Function NameNo.

SYS_CLRSEM

3.2

Num) ;

nfi

Num: semaphore number (0 ~ FFH)
None
None
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.

Co

Format:Input:
Output:Function Value:
Function:ntialFunction
Specifications

de

Title

Title

Function

Function Name

No.

Function
Specifications

Switches System ClockSYS_CHGSYSCK

4.1

Format:Input:

SYS_CHGSYSCK (Uint 32

CkMode) ;SE

GA

Output:Function Value:
Function:
Remarks:void

CkMode: 0: CPU 26 MHz, 320/640 Mode
1: CPU 28 MHz, 352/704 Mode
None
None
System clock is switched to the value specified by CkMode.
See the overview and the SMPC Manual regarding reset devices andprocessing time. The system hangs up when this routine is called via
slave SH2. Be sure to call via master SH2.

Saturn System Library User's Guide

11

Function

Function Name

No.

Function
Specifications

References System Clock ValueSYS_GETSYSCK

4.2

Remarks:

Uint 32

SYS_GETSYSCK ;

None
None
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.
Please reference this value via master SH2.

Title

Function

Function
Specifications

Change SCU Interrupt Routine Priority

5.1*IprTab) ;IprTab: 32 long word data array
None
None
The SCU interrupt routine priority table of the Boot ROM is rewritten
as the table value specified by IprTab. If rewrite is performed once,
interrupt processing by the SCU interrupt routine is executed inaccordance with the priority of the table values pertaining to eachfactor.

The table contents are not checked. If inconsistencies relating to priority exist in the table, thesystem may hang up.

Table settings are valid until the next rewrite. During this interval,
there is no need for the application to save the table specified in theparameters. 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.

Remarks:

Function
Specifications

Function

Function Name

No.

Starts and Executes CD Multiplayer

SYS_EXECDMP

6.1

GA

Title

void

SYS_EXECDMP (void) ;None
Does not return to call side.
None
Starts and executes the CD multiplayer.
The system hangs up when this routine is called via slave SH2.
Be sure to call via master SH2.

SE

Format:Input:
Output:Function Value:
Function:
Remarks:

12

SYS_CHGUIPR (Uint 32

SYS_CHGUIPR

Co

Note:

void

No.

nfi

Format:Input:
Output:Function Value:
Function:

Function NamedeFormat:Input:
Output:Function Value:
Function:

nti
al

Title

Function

Function Name

No.

Function
Specifications

Operates Power On Clear Memory

SYS_PCLRMEM

7.1

Format:Input:
Output:Function Value:
Function:*SYS_PCLRMEM

Perform normal memory access.
Perform normal memory access.
None
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).
A check of the range is not performed. Be careful not to access outside
the range.

SE

GA

Co

nfi

de

Remarks:

Uint8

nti
al

Title

Saturn System Library User's Guide

13

SE

GA

Co

nfi

de

nti
al

(This page is blank in the original Japanese version.)

14

nti
al

SMPC I/F User’s Manual
1.0 GuideThis library uses functions of the SMPC (System Management and Peripheral Control).

2.0 Features

SE

GA

Co

nfi

de

• Able to greatly decrease the main CPU burden.
• The main CPU and SMPC interface is a software handshake method using the
SMPC register.

Saturn System Library User's Guide15

3.0 Overview

nti
al

3.1 Function Overview
SMPC functions can be divided into the system management system and peripheral
control system.
• System Management System
The system management system resets the hardware (CPU, sound, etc.), sets theclock, and performs acquisition.

de• Peripheral Control System
The peripheral control system collects data automatically from peripherals connected to the peripheral I/F, and returns it to the main CPU.

nfi

3.2 Process Overview
The interface between the SMPC and the main CPU is a handshake. In executing afunction (command), required parameters are written to the SMPC register. The
command write procedure is followed. SMPC executes processing in response tocommands when commands are written. Processes include IntBack and NonIntBack.

Co• IntBack
Intback is the process of returning results through interrupts (SMPC interrupts)
after commands are passed to the SMPC. SMPC interrupt processing and registration are performed in the library. Also, other interrupt processes are prohibited during the SMPC interrupt process. Timing of issuing command issuancediffers according to the function.

GA• Non-IntBack
Non-IntBack is a process that only passes commands to the SMPC. The libraryfunction 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 usedby this process are functions which do not have to receive results after a command has been passed.
Shown below are the processing systems that can be used by each function.
O : Processing, X : Not processing

Non-IntBack

System Management

O

O

Peripheral Control

O

X

SE

IntBack

16

4.1 Functions

nti
al

4.0 Details• System Management System
The system management system has the following functions.
Function

IntBack
X

Slave SH2 ON

X

Slave SH2 OFF

X

Sound ONX

CD ON
CD OFF
Entire system reset
NMI Request
Hot reset enable
Hot reset disable
Get cartridge code
Get area code
Get system status

O

O
O

X

O

X

O

X

O

X

O

X

O

X

O

O

X

O

X

O

X

X

O

Get SMPC memoryOX

Set time

X

O

O

X

Get timeCo

Set SMPC memory

O

X

nfi

Sound OFFOdeMaster SH2 ON

Non-IntBack(Note) Clock change 320,352 is provided by the system library.

GA• Peripheral Control System
The following peripherals are supported by the library.
Game Device

SE

Saturn Peripherals

Mega Drive Peripherals

Saturn System Library User's Guide

Peripheral Name
Digital Devices
Analog Devices
Pointing Devices (mouse)
Keyboard
Multitap (6P)
3-button Pad
6-button Pad
4P adapter
Mouse

17

4.2 Processnti
al4.2.1 Library Configuration• Non-IntBack Command IssuanceThis is the Non-IntBack system process.

Gets peripheral data and time data
This is a process required for each frame.
4.2.2 Recommended Examples

de• IntBack Command Issuance
Gets system data (except for time)
This process is performed once per game.

Recommended examples of three patterns are shown below.
1

IntBack
CommnadIssuance

Get system data
Get peripheral data

SE

GA

Co

Get peripheral data and time data

18

3

O

nfi

Non-IntBack Command Issuance

2

O

O

O

O
O
O

• Chart DescriptionsntialMain Process
IntBack initialization (1) : Specifies system data acquisition
IntBack initialization (2) : Specifies peripheral data acquisition
IntBack initialization (3) : Specifies peripheral data acquisition and time dataacquisitionde

SMPC Process(1) : System data collection process(2) : Peripheral data collection process(3) : Time data collection process

*

*

SE

GA

Co

nfi

(1) Pattern 1

Saturn System Library User's Guide

19

nti
al
de
nfi
Restrictions

Co

4.2.3

SE

GA

• Common• 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-BlankIN.
• Cautions when executing in multiple tasks
In cases in which the interrupt task is changed when using the library withmultiple tasks, because SMPC exclusive control is not performed in the library,
SMPC deadlock may occur and SMPC operation may become abnormal. As aresult, when executing with multiple tasks, the exclusive control of library mustbe performed by the user.
• For restrictions from slave SH2 see the SMPC User’s Manual.
• 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

System Data Acquisition (Excluding time)ntial• IntBack Command Issue Function• There are no restrictions other than Common (above).

Peripheral Data Acquisition, Time Data Acquisition• Do not issue a command after issuing the IntBack command until the next V-Blank

SE

GA

Co

nfi

de

IN.
• Issue a IntBack command 14 ms before the specified V-Blank IN.
• The peripheral data collection process within SMPC is done during one verticaldisplay 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.
• 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.
• Number of V-Blank IN Skips
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 isprovided 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.

Saturn System Library User's Guide21

4.3 Peripheral Control

4.3.1

nti
al

Peripheral controls must be created in accordance with game creation standards.
The library is created intelligently, thus enabling them to be created easily.
PolicyThe peripheral acquisition process is created according to the following policies forflexible 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.
Methodde

4.3.2(Example)

Co

Input
Required number of peripherals = 3
Peripheral ID = digital device
Peripheral size = digital device sizenfi(1) Overview• Each peripheral IDs and peripheral data is obtained by specifying as inputs therequired 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.

OutputGA

Connection Status
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)

Peripheral ID

Peripheral Data

DigitalNo. 2

Unconnected

InvalidNo. 3

AnalogDigital Format

SE

No. 1

22

Digital Format

5.0 Calling SequencentialRecommended example of pattern 3 calling sequence.
Uint32 work[10];PerGetSys *sys_data;/*/*

peripheral data acquisition work areasystem data*/*/

PerDgtInfo *get_per;
Uint8 *get_tim;/*/*

peripheral output data pointertime output data pointer*/*/• Initial Process (Immediately after the V-Blank Process).

/* get system data is specified*/

sys_data = PER_GET_SYS () ;/*de

PER_Init (PER_KD_SYS, 0, 0, 0, NULL, 0);. . .

get system data*/

• Normal (Immediately after the V-Blank Process).

nfi

PER_Init (PER_KD_PERTIM, 3, PER_ID_DGT, PER_SIZE_DGT, work, 0);/* Peripheral data and time data acquisition are specified */...

• Normal for 2 or more times (Immediately after the V-Blank Process).

SE

GA

Co

PER_GetPer (PerGetPer **) &get_per); /* get peripheral data */get_tin = PER_GET_TIM ();/* get time*/if (((get_per[2].data) & PER_DGT_U) == PER_DGT_U_) { /* current peripheral data of connector 3 is UP ? */
. . .
. . .

Saturn System Library User's Guide23

6.1 List of Data
Function
IntBack

Peripheral ID data type
Peripheral size data type
IntBack Kind
Required number of peripherals
System data output data type
Peripheral data output data type
Device information data type

Digital device info data type

No.

PerId

1

PerSize

2

PerKind3

PerNum4

PerGetSys

5

PerGetPer

6

PerDgtInfo

7

8

Pointing device info data type

PerPntInfo

9

Keyboard device info data type

PerKbdInfo

10

deMega Drive 3-button pad info data type PerM3bpInfo

11

Mega Drive 6-button pad info data type PerM6bpInfo

12

Digital device data type

13

PerAnlData

14

Pointing device data type

PerPntData

15

Keyboard device data type

PerKbdData

16

Mega Drive 3-button pad data type

PerM3bpData

17

Mega Drive 6-button pad data type

PerM6bpData

18

Co

nfi

PerDgtData

Analog device data type

GA
SE
24

Function name

PerAnlInfo

Analog device info data type

Device Data Typenti
al

6.0 Data Specifications

Data Specifications

IntBack command issuance
Title

Data

Data
Peripheral ID data typeSpecifications

This data type shows the peripheral ID.
Constant name

Description

nti
al

6.2

Data Name

No.

PerId

1

Unconnected

PER_ID_UNKNOW

Peripherals that cannot be processed by SMPCPER_ID_DGTDigital Device

PER_ID_ANL

Analog Device

PER_ID_PNT

Pointing Device (Mega Drive mouse)

PER_ID_KBD

Keyboard

PER_ID_M3BP

Mega Drive 3-button pad

PER_ID_M6BP

Mega Drive 6-button pad

nfi

Title

de

PER_ID_NCON

Data

Data
Peripheral size data typeSpecifications

Data NameNo.

PerSize2

Constant name
PER_SIZE_DGT
PER_SIZE_ANL
PER_SIZE_PNT
PER_SIZE_KBD
PER_SIZE_M3BP

Description

Digital Device

Analog Device

Pointing Device (Mega Drive mouse)
Keyboard

Mega Drive 3-button pad
Mega Drive 6-button pad

SEGA

PER_SIZE_M6BP

Co

This data type shows the peripheral size.

Saturn System Library User's Guide

25

Data

Data
IntBack kind data typeSpecifications

Data NameNo.

PerKind

3

nti
al

Title

This data type shows the IntBack kind.
Constant name

Description

PER_KD_SYS

System data acquisition (except time)

PER_KD_PER

Peripheral data acquisition

PER_KD_PERTIM

Peripheral data acquisition + time data acquisition

Data

Data
Required number of peripherals data typeSpecifications

Data Name

No.

de

Title

4

Data NameNo.

PerGetSys

5

PerNumThis data type shows the required number of peripherals.
Meaning

0 ~ 31

1P ~ 32P

Data

Co

Data
System data output data typeSpecifications

nfi

Title

Value

This data type shows the system data output.
PerGetSys *data
Access Macro
PER_GS_AC (data)
PER_GS_SS (data)
PER_GS_SM (data)SE
26

Description

Area code

Uint16

System status

Uint32

SMPC memory

Uint8

SMPC statusGA

PER_GS_SMPC_STAT (data)

Type

Uint8

Shown below are the constants and values that can be used by each access macro.

bit 7
0

bit 0
0

0

0

0

0

CTR1

PER_GS_AC (data)
bit 7
0

nti
al

PER_GS_CC (data)

CTR0

bit 0
0

0

ACODE ACODE ACODE ACODE

0

3

2

1

0

de

See the hardware manual for areas indicated an area codes.
PER_GS_SS (data)
Bit Position ConstantAcquisition ValueDOTSEL signal status

PER_SS_SYSRESSYSRES signal status

PER_SS_MSHNMI

MSHNMI signal statusnfi

PER_SS_DOTSELPER_SS_SNDRESSNDRES signal status

PER_SS_CDRES

CDRES signal status

Description of Acquisition Values
Value
1

Co

0

MeaningOFF
ON

PER_GS_SM (data)
Areas which are used in common by applications and Boot ROM.
Bit Position ConstantAcquisition ValuePER_MSK_LANGU

Language (see below)

SE (0: ON, 1: OFF)PER_MSK_STEREOSTEREO or MONO (0: STEREO, 1: MONO)

PER_MSK_HELP

HELP (0: ON, 1: OFF)GA

PER_MSK_SE

Language Constant
ConstantSE

PER_JAPAN
PER_ENGLISH
PER_FRANCAISPER_DEUTSCH
PER_ITALIANOPER_ESPNOL

Description

Japanese
EnglishFrenchGermanItalian
SpanishSaturn System Library User's Guide

27

PER_GS_SMPC_STAT (data)
Acquisition ValuePER_SS_RESET

Reset mask condition
0: reset enable
1: reset disable (default)

PER_SS_SETTIMETime set condition
0: time is not set after SMPC cold reset
1: time is set after SMPC cold reset

Data

Data
Peripheral data output data typeSpecifications

This data type shows peripheral data output.

Title

Data

Data
Digital device information data typeSpecifications

No.

PerGetPer

6

Data NameNo.

PerDgtInfo

7

nfi• Device Information Data Type

Data Name

de

Title

nti
al

Bit Position ConstantThis data type shows digital device information.

Title

{
data;
push;
id;

Data

/*
/*

digital device
current peripheral data/*previously not pressed currently pressed button *//*peripheral ID

Co

typedef struct
PerDgtData
PerDgtData
PerId} PerDgtInfo;

Data
Analog device information data typeSpecifications

*/
*/
*/

Data NameNo.

PerAnlInfo

8

GA

This data type shows analog device information.

SE

typedef struct
PerAnlData
PerAnlData
PerId} PerAnlInfo;

28

{
data;
push;
id;

/*
/*

analog device
current peripheral data

*/
*/

/*

previously not pressed currently pressed button *//*peripheral ID*/

TitleData

This data type shows pointing device information.
typedef struct
PerPntData
PerPntData
PerId} PerPntInfo;

Title

{
data;
push;
id;

Data NameNo.

PerPntInfo

9

nti
al

Data
Pointing device information data typeSpecifications/*/*

pointing device
current peripheral data/*previously not pressed currently pressed button *//*peripheral ID

Data

*/

Data NameNo.

PerKbdInfo

10

de

Data
Keyboard device information data typeSpecifications*/*/

This data type shows keyboard device information.

Title

{
data;
push;
id;

/*
/*

keyboard device
current peripheral data/*previously not pressed currently pressed button *//*peripheral ID

nfi

typedef struct
PerKbdData
PerKbdData
PerId} PerKbdInfo;

Data

Data
Mega Drive 3-button pad information data typeSpecifications

*/
*/
*/

Data NameNo.

PerM3bpInfo

11

Co

This data type shows Mega Drive 3-button pad information.
typedef struct
PerM3bpData
PerM3bpData
PerId} PerM3bpInfo;

Title

Data

{
data;
push;
id;

/*
/*

Mega Drive 3-button pad
current peripheral data/*previously not pressed currently pressed button *//*peripheral ID

GA

Data
Mega Drive 6-button pad information data typeSpecifications

*/
*/
*/

Data NameNo.

PerM6bpInfo

12

This data type shows Mega Drive 6-button pad information.
{
data;
push;
id;

/*
/*

Mega Drive 6-button pad
current peripheral data

*/
*/

/*

previously not pressed currently pressed button *//*peripheral ID*/

SE

typedef struct
PerM6bpData
PerM6bpData
PerId} PerM6bpInfo;

Saturn System Library User's Guide

29

Description of Acquisition Values
Value

Meaning0

Button is pressed1

Button is not pressed

Data
Specifications

Data

Data Name

No.

Digital device data type

PerDgtData

13

This data type shows the digital device.
typedef Uint16

PerDgtData;

Bit Position ConstantAcquisition Value

de

Title

nti
al

• Device Data TypeThe meaning of the device data bit acquisition value is explained below.

/* digital device data type */UP

PER_DGT_D

DOWN

PER_DGT_R

RIGHT

PER_DGT_L

LEFT

PER_DGT_A

A

PER_DGT_B

B

PER_DGT_C

C

PER_DGT_S

START

PER_DGT_X

X

PER_DGT_Y

Y

PER_DGT_Z

Z

PER_DGT_TR

TRG-RIGHT (upper right of the device)

PER_DGT_TL

TRG-LEFT (upper left of the device)

Data
Specifications

Co

Data

Data Name

No.

Analog device data type

PerAnlData

14/* analog device data type/* digital device data type/* X axis absolute value (0 ~ 255)/* Y axis absolute value (0 ~ 255)/* Z axis absolute value (0 ~ 255)

*/
*/
*/
*/
*/

GA

Title

nfi

PER_DGT_U

This data type shows the analog device.
{
dgt;
x;
y;
z;

SE

typedef struct
PerDgtData
Sint16
Sint16
Sint16} PerAnlData;

30

Data
Specifications

Data

Data NameNo.

Pointing device data type

PerPntData

15

nti
al

Title

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/* amount of X axis movement (-128 ~ 127)/* amount of Y axis movement (-128 ~ 127)

*/
*/
*/
*/
*/

de

Shown below are constants and values that can be used by each member.
Data
Bit Position ConstantAcquired value

RIGHT

PER_PNT_L

LEFT

PER_PNT_MID

MIDDLEPER_PNT_CNT

CENTERPER_PNT_X0

X axis overflow (0: overflows, 1: does not overflow)

PER_PNT_Y0

Y axis overflow (0: overflows, 1: does not overflow)

nfi

PER_PNT_R

Data

Data
Specifications

Keyboard device data type

Co

Title

Data NameNo.

PerKbdData

16

This data type shows the keyboard device.
typedef struct
PerDgtInfo
Uint8
Uint8
} PerKbdData;

{
dgt;
skey;
key;

/* keyboard device data type/* digital device data type/* special key/* key

*/
*/
*/
*/

GA

Shown below are constants and values that can be used by each member.
skey
Bit Position ConstantAcquired value
Caps Lock

PER_KBD_NL

Num Lock

PER_KBD_SL

Scroll Lock

PER_KBD_MK

Make (0: key pressed, 1: key not pressed)

PER_KBD_BR

Break (0: key released, 1: key not released)SE

PER_KBD_CL

Saturn System Library User's Guide

31

Data
Specifications

Data

Data NameNo.

Mega Drive 3-button pad data type

PerM3bpData

17

nti
al

Title

This data type shows the Mega Drive 3-button pad.
typedef Uint8

PerM3bpData;/* Mega Drive 3-button pad data type*/

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.

PER_M3BP_U

UP

PER_M3BP_D

DOWN

PER_M3BP_R

RIGHT

PER_M3BP_L

LEFT

PER_M3BP_A

A

PER_M3BP_B

B

PER_M3BP_C

C

PER_M3BP_S

START

de

Acquired Value

Data

Data
Specifications

Mega Drive 6-button pad data type

Co

Title

nfi

Bit Position Constant

Data NameNo.

PerM6bpData

18

This data type shows the Mega Drive 6-button pad.
typedef Uint16

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 ConstantAcquisition ValueUP

PER_M6BP_D

DOWN

PER_M6BP_R

RIGHT

PER_M6BP_L

LEFT

PER_M6BP_A

A

PER_M6BP_B

B

PER_M6BP_C

C

PER_M6BP_S

START

PER_M6BP_X

X

SE

GA

PER_M6BP_U

PER_M6BP_Y

Y

PER_M6BP_Z

Z

PER_M6BP_MD

MODE (upper right of device)32*/

7.0 Function Specifications

nti
al

7.1 List of Functions
Function
Non-IntBack

Command Issue

Master SH2 ON
Slave SH2 ON
Slave SH2 OFF
Sound ON
Sound OFF2

PER_SMPC_SSH_OFF

3

PER_SMPC_SND_ON

4

6

PER_SMPC_CD_OFF

7

PER_SMPC_SYS_RES

8

NMI request

PER_SMPC_NMI_REQ

9Hot reset enable

PER_SMPC_RES_ENA

10

Hot reset disable

PER_SMPC_RES_DIS

11SMPC memory set

PER_SMPC_SET_SM

12Time set

PER_SMPC_SET_TIM

13

IntBack Initialization

PER_Init

14

de

nfi
Peripheral data acquisition

PER_GetPer

15

Time acquisition

PER_GET_TIM

16

System data acquisition

PER_GET_SYS

17

Hot reset acquisition

PER_GET_HOT_RES

18

Co

Other

1

PER_SMPC_SSH_ON

5

Reset entire system

Other

PER_SMPC_MSH_ON

PER_SMPC_SND_OFF

CD OFF

Command Issue

No.

PER_SMPC_CD_ON

CD ON

IntBack

Function Name

7.2 Function Specifications
Non-IntBack

Function

Function Name

Function
Specifications

Master SH2 ON ~ hot reset disable

PER_SMPC_MSK_ON ~ 1 ~ 11
PER_SMPC_RES_DIS

No.

GA

Title

void PER_SMPC_XXX (void)

None
None
None
As per the list of function specifications. See the SMPC hardware
manual for details.

SE

Format:Input:
Output:Function Value:
Function:

Saturn System Library User's Guide

33

TitleFunction

Format:Input:

Function NameNo.

PER_SMPC_SET_SM

12

nti
al

Function
Sets SMPC memory
Specifications

void PER_SMPC_SET_SM (Uint32 input_dt)

Output:Function Value:
Function:

Function

Function
Sets time
Specifications

Format:Input:

Function NameNo.

PER_SMPC_SET_TIM

13

de

Title

input_dt: SMPC memory
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 thatis used in common by applications and the Boot ROM, the format
must be observed.

void PER_SMPC_SET_TIM (Uint8

input_dt: time

nfi

Input Format* input_dt)

bit7

bit4

bit3

bit0

second (10 digit)

second (1 digit)*(input_dt + 1)

minute (10 digit)

minute(1 digit)*(input_dt + 2)

hour (10 digit)

hour (1 digit)*(input_dt + 3)

day (10 digit)

day (1 digit)*(input_dt + 4)

day of week (0 ~ 6)month (1H ~ CH)*(input_dt + 5)

year (10 digit)

year (1digit)

year (1000 digit)

year (100 digit)*(input_dt + 6)

Co*(input_dt)• Day data: Sunday is 0, Monday is 1, Tuesday is 2 . . .
• Month data is hexadecimal data.

None
None
Sets the time.

SE

GA

Output:Function Value:
Function:

34

IntBack
Function

Function Name

No.

Function
Specifications

Initializes IntBack

PER_Init

14

nti
al

Title

Format:Uint32 PER_Init (PerKind kind, PerNum num, PerId id,
PerSize size, Uint32 work[n], Uint8 v_blank)

Input:

kind
num
id
size
work

• Method for calculating the work areanfi

n = (num x data A)/4 + data B
round up to nearest digitdev_blank: IntBack type
: Required number of peripherals: Peripheral ID: Peripheral size
: Work area (Use for getting peripheral data. Must be
declared by a global variable.): Number of V-Blank skip

Data A and data B change depending on the peripheral.
Peripheral
Digital device

12

1
2

36

2

Keyboard device

20

1

Mega Drive 3-button pad

61

Mega Drive 6-button pad

12

1

Co

Pointing device

none
execution condition

GA

Constant

Description

PER_INT_ERR

Could not issue the IntBack command

PER_INT_OK

Could issue the IntBack command

Function:SE

Remarks:
Note:

Data B36

Analog device

Output:Function Value:

Data A

Initializes IntBack and issues the IntBack command. Execution rules
must be obvserved. Set Null or 0 to unneeded parameters. Execute atleast 1 time before executing PER_GetPer (), PER_GetTim(),
PER_GetSys().
Generally, this should be executed immediately after the V-Blank
process. Other interrupts are prohibited during SMPC interrupts.
DO NOT perform this function within the interrupt process. Be sureto perform via the main process.

Saturn System Library User's Guide

35

Function

Function Name

No.

Function
Specifications

Peripheral data acquisition

PER_GetPer

15

Format:Input:
Output:Function Value:

nti
al

Title

Uint32 PER_GetPer (PerGetPer **output_dt)

none
output_dt: peripheral output address (Null = cannot get)Execution conditions.
Constant

Title

Could not issue the IntBack command.

PER_INT_OK

Could not issue the IntBack command.

Issues the IntBack command and gets peripheral data. Execution
rules must be observed. Before this function is executed, specify “peripheral data get” to PER_Init() and execute at least once. Null is
output to the peripheral data address when peripheral data get is not
specified.
Generally, this should be executed immediately after the V-Blank
process. Other interrupts are prohibited during SMPC interrupt.

deRemarks:

PER_INT_ERR

nfi

Function Value:

Function

Function
Gets time
Specifications

Uint8

16

*PER_GET_TIM (void)

Gets system data

GA

Function

Function
Specifications

PerGetSys

Function NameNo.

PER_GET_SYS

17*PER_GET_SYS (void)

none
none
System data address (NULL = could not get)Gets system data. Instructs system data get to PER_Init () before thisfunction is executed and execute at least once. Execute this function
about 300 µs after executing PER_Init.

SE
36

No.

PER_GET_TIM

none
none
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.

Title

Format:Input:
Output:Function Value:
Function:

Function NameCo

Format:Input:
Output:Function Value:
Function:

DescriptionOtherFunction

Function Name

Function
Gets hot reset
Specifications

Format:Input:
Output:Function Value:

PER_GET_HOT_RES

18

Uint8 PER_GET_HOT_RES (void)

none
none
Hot reset condition address
Constant

Description

Hot reset ON

PER_HOT_RES_OFF

Hot reset OFFdePER_HOT_RES_ON

Gets the hot reset condition. This function can be executed at any
time. Update is performed by PER_GetPer().

SE

GA

Co

nfi

Function:

No.

nti
al

Title

Saturn System Library User's Guide

37

SE

GA

Co

nfi

de

nti
al

(This page is blank in the original Japanese version.)

38

1.0

nti
al

Backup Library User’s Manual
Guide

1.1 Purpose
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.

1.2 Explanation
1.2.1 IntroductiondeThis library provides functions for reading, writing and searching these backup
storage devices.

1.2.2 How to Use This Librarynfi

Always use this library when accessing storage devices for backup.
The library itself is compressed and stored in the boot ROM. The application programmer 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
can be used.

Co

1.2.3 Storage Capacity

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 (thecapacity of each partition may be different).

GA

When storing data, execute BUP_SelPart() and BUP_Stat() and confirm the capacity
before writing. The built-in backup memory is 32 Kbyte.
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

SE

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
PER_SMPC_RES_DIS() in the system library.

Saturn System Library User's Guide

39

#include “sega_per.h”#define BUP_START_ADDR#include “sega_bup.h”/*sets write address for library

BackUpRamWork[2048];

main()[
BupConfig
BupStat
BupDir
BupDateUnit8

conf[3]sttb;
writetb;
datatb;*time;

deUnit32

0x60????0nti
al

1.3 Program Example
An example of a program written in C is shown below.

SE

GA

Co

nfi

PER_SMPC_RES_DIS();/*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) {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+ (Uint16 )(time[5]>>4)* 10+ (Uint16 )(time[5] & 0x0F) - 1980);
datetb.month = time[4] & 0x0F;
datetb.day= (time[3]>>4)*10 + (time[3] & 0x0F);
datetb.time = (time[2]>>4)*10 + (time[2] & 0x0F);
datetb.min= (time[1]>>4)*10 + (time[1] & 0x0F);
writetb.date= 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

40

*/

*/

*/

*/

*/
*/

2.1 Data List
Title
Data specification

nti
al

2.0 Reference

Data
Storage device connection information
typedef struct BupConfig {Uint16 unit_id;
Uint16 partition;} BupConfig;

Data Name
BupConfig

No.

/*unit ID/*number of partitions*/*/*When unit_id is "0", it indicates non-connection.

Title
Data specification

Function
Status information

unit_id1
2

partition
11deType of device
Built-in memory
External cartridge

No.

Co

nfi

typedef struct BupStat {Uint32 totalsize;
Uint32 totalblock;Uint32 blocksize;
Uint32 freesize;
Uint32 freeblock;Uint32 datanum;} BupStat;

Function Name
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

*/
*/
*/
*/
*/
*/

The value for the size specified by BUP_Stat() for datasize is stored in datanum.
Title
Data specification

Function
Date and time/*year (1980 subtracted from year/*month (1-12)/*day (1-31)/*hour (0-23)/*minute (0-59)/*day of week (sunday 0- saturday 6)

No.

*/
*/
*/
*/
*/
*/

SE

GA

typedef struct BupStat {Uint8 year;
Uint8 month;
Uint8 day;Uint8 time;
Uint8 min;Uint8 week;} BupDate;

Function Name
BupDateSaturn System Library User's Guide

41

Function
Directory information

Function Name
BupDirtypedef struct BupStat {Uint8
filename[12];comment[11];Uint8

language;

Uint32
Uint32
Uint16} BupDir;

date;
datasize;blocksize;

nfi

2.2 Function List
Function/*file name/*total 12 bytes ASCII 11 characters+ NUL/*comment/*total 11 bytes ASCII 10 characters+ NUL/*language of comment/* Japanese
BUP_JAPANESE/* English
BUP_ENGLISH/* French
BUP_FRACAIS/* German
BUP_DEUTSCH/* Spanish
BUP_ESPAN0L/* Italian
BUP_ITALIANO/*date and time data/*data size (unit: byte)/*data size (unit: block)

de

Uint8

SE

GA

Co

Backup library
Initialize backup library
Select partition
Execute format
Get status
Write data
Read data
Delete data
Get directory information
Verify data
Open date and time data
Compress data and time data

42

No.

nti
al

Title
Data specification

Function NameNo.

BUP_Init
BUP_SelPart
BUP_Format
BUP_Stat
BUP_Write
BUP_Read
BUP_Delete
BUP_Dir
BUP_Verify
BUP_GetDate
BUP_SetDate

1
2
3
4
5
6
7
8
9
10
11

*/

*/
*/

*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/

WriteStorage device
for backup

HOST
Read

2.4 Function Specifications

OutputFunction

void

Function Name
BUP_Init

No.
1

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 securewith Uint32.
conf: 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.

nfi

FormatInput

Function
Initializes backup library

de

Title
Function specificationnti
al

2.3 Data FlowCo

The following device numbers correspond to three tables.
Device No.

0
1
2

Notes
ExampleDevice Type

Built-in memory cartridge
Memory cartridge or parallel interface
Serial interface

Always prepare three storage device connection information tables.

GA#define BUP_START_ADDR 0x6??????
#include”sega_bup.h”
Uint32 workmemory[2048]
voidsample(){
BupConfig

conf[3]

BUP_Init(BUP_START_ADDR, workmemory, conf);...............

SE}

Saturn System Library User's Guide

43

Sint32

Title
Function specification

Format
Input

No.
3

device : device number
0: built-in memory
1: memory cartridge or parallel interface
2: serial interfacenone
0: success
BUP_WRITE_PROTECT: write protectedother: failure
Initializes the backup storage device.
Formats only the current partition in a partitioned backup storage
device.

SE
44

Function NameBUP_Format

BUP_Format(Uint32 device)

GA

Function

Function
Executes format

Sint32

OutputFunction value

BUP_SelPart(Uint32 device,Uint16 num)deFunctionNo.
2device : device number
0: built-in memory
1: memory cartridge or parallel interface
2: serial interface
num: partition number
0 - (number of partitions - 1)none
0
: successother : failure
Selects a partition. In the initial condition, partition 0 is selected.

nfi

OutputFunction value

Function NameBUP_SelPart

Co

FormatInput

Function
Partition selection

nti
al

Title
Function specification

Function
Gets status

Function NameBUP_Stat

No.
4

nti
al

Title
Function specification

FormatSint32*stat)

Input

device : device number
0: built-in memory
1: memory cartridge or parallel interface
2: serial interface
datasize: specify size of data to be written in byte units
stat : status information
returns device status0: success
BUP_NON: not connected
BUP_UNFORMAT : not formatted
Gets status information.

Title
Function specification

FormatFunction
Writes data
Sint32No.
5

Co

device : device number
0: built-in memory
1: memory cartridge or parallel interface
2: serial interface
dir : file control information (input other than dir.blocksize)
data : pointer for write data
owsw: overwrite check mode
ON: does not write if file of same name exists
OFF: writes on file if file of same name exists
none
0: success
BUP_NON: not connected
BUP_UNFORMAT: not formatted
BUP_WRITE_PROTECT: write protect exists
BUP_FOUND: file of same name exists
Other: failure
Writes data to the backup storage device.

GA

OutputFunction value

Function Name
BUP_Write

BUP_Write(Uint32 device, BupDir *dir,Uint8 *data,Uint8

owsw)

Input

de

Function

nfi

OutputFunction value

BUP_Stat(Uint32 device,Uint32 datasize,BupStat

SE

Function

Saturn System Library User's Guide

45

FormatFunction
Loads data

Sint32*data)

Function NameBUP_Read

No.
6

nti
al

Title
Function specification

BUP_Read(Uint32 device, Uint8 *fname, Uint8

device : device number
0: built-in memory
1: memory cartridge or parallel interface
2: serial interface
fname : file name specification (11 characters are required in ASCII)
Outputdata : pointer for load destination buffer
Function value 0: success
BUP_NON: not connected
BUP_UNFORMAT: not formatted
BUP_NOT_FOUND : file not found
BUP_BROKEN: file is damaged
Other: failure
Function
Loads data from the backup storage device.

Sint32SE

Function46

BUP_Delete(Uint32 device, Uint8 *fname)GA

OutputFunction value

Function NameBUP_Delete

device : device number
0: built-in memory
1: memory cartridge or parallel interface
2: serial interface
fname : file name (11 characters is required in ASCII)
none
0: success
BUP_NON: not connected
BUP_UNFORMAT: not formatted
BUP_NOT_FOUND: file not found
BUP_WRITE_PROTECT: write protect exists
Other: failure
Deletes data on the backup storage device.

Co

FormatInput

Function
Deletes data

nfi

Title
Function specification

de

Input

No.
7

Format
Input

Sint32Function NameBUP_DirNo.
8

BUP_Dir(Uint32 device,Uint8 *fname,Uint16 dirsize, BupDir *dir)device : device number
0: built-in memory
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
dir : stores directory information
number of directory information hits
The file name is done by searching forward, and the directory information is stored in a table. The number of directories hit by the searchis 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 thesign (if the result is 11 when the tbsize is set to 10 and a search is
performed, -11 is returned).
Function
Verify data

Function Name
BUP_VerifyNo.
9FormatSint32*data)

BUP_Verify(Uint32 device, Uint8 *filename,Uint8

Input

device: device number
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

OutputFunction value

Co

Title
Function specification

nfi

de

OutputFunction value
Function

Function
Gets directory information

nti
al

Title
Function specificationGAfilename
data
none
0
: success
BUP_NON: not connected
BUP_UNFORMAT: not formatted
BUP_NO_MATCH: data do not agree
BUP_NOT_FOUND : file not found
BUP_BROKEN: file is damaged
Verifies data written to the backup file.

SE

Function

Saturn System Library User's Guide

47

void

pdate : data and time data of directory information
date : date and time table
none
none
Expands the date and time data in the directory information table.

Title
Function specification

FunctionCompress date and time data

Uint32No.
11date : date and time tablenone
Data in date and time data form in the directory information table.
Compresses the date and time data in the directory information table.

GA
SE
48

Function NameBUP_SetDate

BUP_SetDate(BupDate *date)

Co

FormatInput
OutputFunction value
Function

No.
10

BUP_GetDate(Uint32 pdate,BupDate *date)deOutputFunction value
Function

Function NameBUP_GetDate

nfi

FormatInput

Function
Expands data and time data

nti
al

Title
Function specification