├── .cdtproject
├── .github
└── workflows
│ └── compilation.yml
├── .gitignore
├── .project
├── AUTHORS
├── CMakeLists.txt
├── ChangeLog
├── ID
├── LICENSE
├── Makefile
├── README.md
├── STATUS
├── ee
├── dma
│ ├── include
│ │ ├── dmaArrays.h
│ │ ├── dmaCore.h
│ │ ├── dmaInit.h
│ │ ├── dmaKit.h
│ │ └── dmaSpr.h
│ └── src
│ │ ├── dmaCore.c
│ │ ├── dmaInit.c
│ │ └── dmaSpr.c
├── gs
│ ├── include
│ │ ├── gsCore.h
│ │ ├── gsFontM.h
│ │ ├── gsHires.h
│ │ ├── gsInit.h
│ │ ├── gsInline.h
│ │ ├── gsKit.h
│ │ ├── gsMisc.h
│ │ ├── gsPrimitive.h
│ │ ├── gsTexManager.h
│ │ ├── gsTexture.h
│ │ └── gsVU1.h
│ └── src
│ │ ├── gsCore.c
│ │ ├── gsFontM.c
│ │ ├── gsHires.c
│ │ ├── gsInit.c
│ │ ├── gsMisc.c
│ │ ├── gsPrimitive.c
│ │ ├── gsTexManager.c
│ │ ├── gsTexture.c
│ │ └── gsVU1.c
└── toolkit
│ ├── include
│ └── gsToolkit.h
│ └── src
│ └── gsToolkit.c
├── examples
├── alpha
│ ├── alpha.c
│ └── alpha.tiff
├── atlas
│ ├── atlas.c
│ └── runner_atlas.png
├── basic
│ └── basic.c
├── bigtex
│ ├── bigtex.bmp
│ ├── bigtex.c
│ ├── bigtex.jpg
│ └── bigtex.raw
├── clut
│ └── clut.c
├── clutcsm
│ └── clutcsm.c
├── coverflow
│ ├── coverflow.c
│ └── covers
│ │ ├── game1_512_512_08bit.bmp
│ │ ├── game2_512_512_08bit.bmp
│ │ ├── game3_512_512_08bit.bmp
│ │ ├── game4_512_512_08bit.bmp
│ │ └── game5_512_512_08bit.bmp
├── cube
│ ├── cube.c
│ └── mesh_data.c
├── fb
│ ├── bsdgirl.bmp
│ └── fb.c
├── fhdbg
│ ├── fhdbg.c
│ └── images
│ │ ├── fhdbg_01.jpg
│ │ ├── fhdbg_02.jpg
│ │ └── fhdbg_03.jpg
├── font
│ ├── arial.fnt
│ ├── dejavu.bmp
│ ├── dejavu.dat
│ ├── dejavu.png
│ ├── font.c
│ └── lucida.fnt
├── fontm
│ ├── fontm.c
│ └── test.bmp
├── hires
│ ├── bigtex.bmp
│ ├── bigtex.jpg
│ ├── fhdbg.jpg
│ ├── main.c
│ └── teapot.c
├── linuz-texture
│ ├── sample.c
│ ├── testorig.bmp
│ ├── testorig.jpg
│ ├── testorig.ppm
│ ├── testorig.s
│ └── texture.c
├── modetest
│ ├── modetest.c
│ └── pad.c
├── modetesthires
│ ├── modetesthires.c
│ └── pad.c
├── pixelperfect
│ ├── 128x128.png
│ ├── 132x132.png
│ └── pixelperfect.c
├── png-texture
│ ├── test.png
│ └── textures.c
├── texstream
│ ├── texstream.c
│ └── texstream.png
├── textures
│ ├── bitmap.raw
│ ├── bsdgirl.bmp
│ ├── bsdgirl.jpg
│ ├── ps2dev.jpg
│ └── textures.c
└── vsync
│ └── vsync.c
├── gsKit.pc.cmakein
└── setup.sh
/.cdtproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | -
8 |
9 |
10 |
11 |
12 | -
13 |
14 |
15 |
16 | -
17 |
18 |
19 | gmake
20 | all
21 | false
22 | false
23 |
24 |
25 | gmake
26 | all
27 | false
28 | false
29 |
30 |
31 | gmake
32 | all
33 | false
34 | false
35 |
36 |
37 | gmake
38 | clean
39 | false
40 | false
41 |
42 |
43 | gmake
44 | test
45 | false
46 | false
47 |
48 |
49 | gmake
50 | all
51 | false
52 | false
53 |
54 |
55 | gmake
56 | clean
57 | false
58 | false
59 |
60 |
61 | gmake
62 | test
63 | false
64 | false
65 |
66 |
67 | gmake
68 | all
69 | false
70 | false
71 |
72 |
73 | gmake
74 | test
75 | false
76 | false
77 |
78 |
79 | gmake
80 | clean
81 | false
82 | false
83 |
84 |
85 | gmake
86 | all
87 | false
88 | false
89 |
90 |
91 | gmake
92 | clean
93 | false
94 | false
95 |
96 |
97 | gmake
98 | all
99 | false
100 | false
101 |
102 |
103 | gmake
104 | clean
105 | false
106 | false
107 |
108 |
109 | gmake
110 | test
111 | false
112 | false
113 |
114 |
115 | gmake
116 | all
117 | false
118 | false
119 |
120 |
121 | gmake
122 | clean
123 | false
124 | false
125 |
126 |
127 | gmake
128 | all
129 | false
130 | false
131 |
132 |
133 | gmake
134 | clean
135 | false
136 | false
137 |
138 |
139 | gmake
140 | reset
141 | false
142 | false
143 |
144 |
145 | gmake
146 | all
147 | false
148 | false
149 |
150 |
151 | gmake
152 | clean
153 | false
154 | false
155 |
156 |
157 |
158 |
159 |
160 |
--------------------------------------------------------------------------------
/.github/workflows/compilation.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | pull_request:
6 | repository_dispatch:
7 | types: [run_build]
8 |
9 | jobs:
10 | build:
11 | runs-on: ubuntu-latest
12 | container: ps2dev/ps2sdk-ports:latest
13 | steps:
14 | - name: Install dependencies
15 | run: |
16 | apk add build-base git cmake
17 |
18 | - uses: actions/checkout@v4
19 |
20 | - run: |
21 | git config --global --add safe.directory "$GITHUB_WORKSPACE"
22 | git fetch --prune --unshallow
23 |
24 | - name: Compile project with everything enabled
25 | env:
26 | GSKIT_DEBUG: 1
27 | run: |
28 | make -j $(getconf _NPROCESSORS_ONLN) clean
29 | make -j $(getconf _NPROCESSORS_ONLN)
30 | make -j $(getconf _NPROCESSORS_ONLN) install
31 |
32 | - name: Get short SHA
33 | id: slug
34 | run: echo "sha8=$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_OUTPUT
35 |
36 | - name: Upload artifacts
37 | if: ${{ success() }}
38 | uses: actions/upload-artifact@v4
39 | with:
40 | name: gsKit-samples-${{ steps.slug.outputs.sha8 }}
41 | path: build/*.elf
42 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | *.a
3 | *.elf
4 | build/
5 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | gsKit
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.make.core.makeBuilder
10 |
11 |
12 | org.eclipse.cdt.core.errorOutputParser
13 | org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.VCErrorParser;
14 |
15 |
16 | org.eclipse.cdt.make.core.fullBuildTarget
17 | clean all
18 |
19 |
20 | org.eclipse.cdt.make.core.incrementalBuildTarget
21 | all
22 |
23 |
24 | org.eclipse.cdt.make.core.enableAutoBuild
25 | false
26 |
27 |
28 | org.eclipse.cdt.make.core.buildLocation
29 |
30 |
31 |
32 | org.eclipse.cdt.make.core.enableFullBuild
33 | true
34 |
35 |
36 | org.eclipse.cdt.make.core.enabledIncrementalBuild
37 | true
38 |
39 |
40 | org.eclipse.cdt.make.core.enableCleanBuild
41 | true
42 |
43 |
44 | org.eclipse.cdt.make.core.cleanBuildTarget
45 | clean
46 |
47 |
48 | org.eclipse.cdt.make.core.useDefaultBuildCmd
49 | false
50 |
51 |
52 | org.eclipse.cdt.make.core.buildArguments
53 |
54 |
55 |
56 | org.eclipse.cdt.make.core.buildCommand
57 | gmake
58 |
59 |
60 | org.eclipse.cdt.make.core.autoBuildTarget
61 | all
62 |
63 |
64 | org.eclipse.cdt.make.core.stopOnError
65 | false
66 |
67 |
68 |
69 |
70 | org.eclipse.cdt.make.core.ScannerConfigBuilder
71 |
72 |
73 | org.eclipse.cdt.make.core.ScannerConfigDiscoveryEnabled
74 | true
75 |
76 |
77 | org.eclipse.cdt.make.core.makeBuilderParserId
78 | org.eclipse.cdt.make.core.GCCScannerInfoConsoleParser
79 |
80 |
81 | org.eclipse.cdt.make.core.esiProviderCommandEnabled
82 | true
83 |
84 |
85 | org.eclipse.cdt.make.core.siProblemGenerationEnabled
86 | true
87 |
88 |
89 | org.eclipse.cdt.make.core.useDefaultESIProviderCmd
90 | true
91 |
92 |
93 | org.eclipse.cdt.make.core.makeBuilderParserEnabled
94 | true
95 |
96 |
97 | org.eclipse.cdt.make.core.esiProviderParserId
98 | org.eclipse.cdt.make.core.GCCSpecsConsoleParser
99 |
100 |
101 |
102 |
103 |
104 | org.eclipse.cdt.core.cnature
105 | org.eclipse.cdt.make.core.makeNature
106 | org.eclipse.cdt.make.core.ScannerConfigNature
107 |
108 |
109 |
--------------------------------------------------------------------------------
/AUTHORS:
--------------------------------------------------------------------------------
1 | # ____ ___ | / _____ _____
2 | # | __ | |___/ | |
3 | # |___| ___| | \ __|__ | gsKit Open Source Project.
4 | # ----------------------------------------------------------------------
5 | # Copyright 2004 - Chris "Neovanglist" Gilbert
6 | # Licenced under Academic Free License version 2.0
7 | # Review gsKit README & LICENSE files for further details.
8 |
9 |
10 | The following people have contributed to the gsKit project:
11 |
12 | Alias | Real Name | e-mail
13 | ------------|-------------------|---------------------
14 | Neovanglist | Chris Gilbert | Neovanglist@LainOS.org
15 | linuzappz | Not Disclosed | linuzappz@pcsx2.net
16 | Hago @ gmx | Not Disclosed | Not Disclosed
17 | Pixel | Not Disclosed | Not Disclosed
18 | yulius | Not Disclosed | Not Disclosed
19 | gawd^ | Not Disclosed | Not Disclosed
20 | jbit | Not Disclosed | Not Disclosed
21 |
22 | People that I'd like to thank, and why:
23 |
24 | emoon - For the BreakPoint Demo Lib, which I have used *so* much code from, and
25 | based a large portion of my learning on. Without this, gsKit would not have
26 | been possible.
27 |
28 | ooPo - For research, documentation, and reference implimentations for the DMAC and GS.
29 |
30 | t0mb0la - For several bugfixes, suggestions, and support.
31 |
32 | Drakonite - Bug fixes, misc. help, and support.
33 |
34 | linuzappz - First working implimentation for texture support, other code contributions.
35 |
36 | Pixel - Tons of help with fontm and other various workings!
37 |
38 | adresd - Help with fontm, and code samples.
39 |
40 | Hajo - BMP/DAT font support, and some PAL/NonInterlaced Fixes.
41 |
42 | yulius - Font support stuffs!
43 |
44 | gawd^ - Using gsKit a lot, getting my butt in gear to fix bugs, and the fb demo!
45 |
46 | jbit - Tons of help tracking down some really nasty texture bugs, plus lending me some code :)
47 |
48 | Shazz - His libtest app has been TONS of help stress/performance testing gsKit.
49 | I've fixed a lot of bugs I would have never otherwise found as a result of it.
50 | (Strange things happen when you start slamming 20k+ tri into a frame!)
51 |
52 | And everyone else from the PS2 Dev community! Thanks!
53 |
--------------------------------------------------------------------------------
/ID:
--------------------------------------------------------------------------------
1 | # ____ ___ | / _____ _____
2 | # | __ | |___/ | |
3 | # |___| ___| | \ __|__ | gsKit Open Source Project.
4 | # ----------------------------------------------------------------------
5 | # Copyright 2004 - Chris "Neovanglist" Gilbert
6 | # Licenced under Academic Free License version 2.0
7 | # Review gsKit README & LICENSE files for further details.
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/LICENSE
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # ____ ___ | / _____ _____
2 | # | __ | |___/ | |
3 | # |___| ___| | \ __|__ | gsKit Open Source Project.
4 | # ----------------------------------------------------------------------
5 | # Copyright 2004 - Chris "Neovanglist" Gilbert
6 | # Licenced under Academic Free License version 2.0
7 | # Review gsKit README & LICENSE files for further details.
8 |
9 | .PHONY: all install
10 |
11 | all:
12 | cmake -S . -B build -Wno-dev "-DCMAKE_TOOLCHAIN_FILE=${PS2SDK}/ps2dev.cmake" "-DCMAKE_INSTALL_PREFIX=${PS2SDK}/ports" -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo "-DCMAKE_PREFIX_PATH=${PS2SDK}/ports"
13 | cmake --build build
14 |
15 | install: all
16 | cmake --build build --target install
17 |
18 | clean:
19 | rm -rf build
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GSKIT
2 |
3 | ```txt
4 | ____ ___ | / _____ _____
5 | | __ | |___/ | |
6 | |___| ___| | \ __|__ | gsKit Open Source Project.
7 | -----------------------------------------------------------------------
8 | Copyright 2004 - Chris "Neovanglist" Gilbert .
9 | All rights reserved.
10 | Licenced under Academic Free License version 2.0
11 | -----------------------------------------------------------------------
12 | ```
13 |
14 | [](https://github.com/ps2dev/gsKit/actions?query=workflow%3ACI)
15 | [](https://github.com/ps2dev/gsKit/actions?query=workflow%3ACI-Docker)
16 |
17 | ## **ATTENTION**
18 |
19 | If you are confused on how to start developing for PS2, see the
20 | [getting started](https://ps2dev.github.io/#getting-started) section on
21 | the ps2dev main page.
22 |
23 | ## Introduction
24 |
25 | gsKit is a library that provides a C interface to the Playstation 2
26 | Graphics Synthesizer. It is low level in nature, implimented using the
27 | PS2SDK and inline assembly. This project does not aim to be all
28 | inclusive, rather a "lean and mean" interface to the GS hardware.
29 |
30 | The following list is of things that, when complete, gsKit will be capable
31 | of when it reaches it's mature stages. It is currently in the early
32 | stages of development. Read the STATUS file for detailed information.
33 |
34 | gsKit aims to provide the following functionality:
35 |
36 | * Multi format GS initialization. (NTSC, PAL, DTV, VESA)
37 | * HalfBuffer Support (`NTSC_I` and `PAL_I` modes)
38 | * VSync, Double Buffering, Anti Aliasing, and Z Depth Test.
39 | * Render Queue Support, with different drawing modes. (`GS_ONESHOT`, and `GS_PERSISTANT`)
40 | * Overlay and multi-context support utilizing the "Merge Circuit".
41 | * Basic primitives as per the Sony documentation. (Line, Tri, TriStrip, ...)
42 | * Extended primitives support. (Quads and GL Style Vertex Lists)
43 | * Simple texture loading and handling.
44 | * Font and printing support for FNT and TrueType formats.
45 | * GS debugging and diagnostic functionality.
46 | * C accessibility of all documented GS functions.
47 |
48 | gsKit also includes a library named dmaKit. dmaKit provides C
49 | routines for DMAC usage by gsKit. The aim of this library is also
50 | for eventual inclusion in [PS2SDK](https://github.com/ps2dev/ps2sdk). For now, it will remain part of the
51 | gsKit project while it matures.
52 |
53 | This library is designed for integration into the PS2SDK when it
54 | becomes mature. As such, it is also designed to link and compile
55 | against the PS2SDK. Support for PS2LIB and other support libraries is
56 | untested.
57 |
58 | ## Project Layout
59 |
60 | A source or binary release of gsKit will include the following
61 | directories:
62 |
63 | * `gsKit/lib` - gsKit compiled libraries.
64 | * `gsKit/doc` - gsKit documentation.
65 | * `gsKit/examples` - Example projects demonstrating use of gsKit.
66 | * `gsKit/ee` - ee root directory.
67 | * `gsKit/ee/gs` - gsKit source root.
68 | * `gsKit/ee/gs/include` - gsKit include files.
69 | * `gsKit/ee/gs/src` - gsKit source files.
70 | * `gsKit/ee/dma` - dmaKit source root.
71 | * `gsKit/ee/dma/include` - dmaKit include files.
72 | * `gsKit/ee/dms/src` - dmaKit source files.
73 | * `gsKit/vu1` - VU1 assembly files.
74 |
75 | ## Installation
76 |
77 | 1. Install PS2Toolchain
78 | In order to install `gsKit`, you must have previously installed the [PS2Toolchain](https://github.com/ps2dev/ps2toolchain)
79 | (which automatically install also the [PS2SDK](https://github.com/ps2dev/ps2sdk))
80 |
81 | 2. Edit your login script
82 | Add this to your login script (example: `~/.bash_profile`)\
83 | `export GSKIT=$PS2DEV/gsKit`
84 |
85 | NOTE: You should have already defined in your login script the `$PS2DEV` variable
86 |
87 | 3. Compile and Install
88 | Run the next command
89 | `make && make install`
90 |
91 | ## Build & Compile Examples
92 |
93 | 1. Install [CMake](https://github.com/Kitware/CMake)
94 |
95 | 2. Build & compile
96 | `make all`
97 |
98 | NOTE: The examples will be in the `build` folder
99 |
100 | ## Important Notes
101 |
102 | There are several small notes that need to be made about gsKit operation.
103 |
104 | * As of version 0.3, gsKit no longer uses the scratchpad, so you are free to
105 | use it in your application.
106 |
107 | * There is a default drawbuffer size of 2MB for oneshot, and 256KB for persistent.
108 | If they are filled beyond capacity, bad things will start to happen.
109 | (Compile with `-DGSKIT_DEBUG` to get warnings about it at the expense of performance
110 | or just uncomment section in Makefile.pref)
111 | You can tweak these values with the `GS_RENDER_QUEUE_(OS/PER)_POOLSIZE` macros.
112 | (Look in ee/gs/include/gsInit.h)
113 |
114 | * Most gsKit routines (prim pushing, `TEST`/`CLAMP` mode setting, etc) will queue their
115 | execution into the drawbuffer. Texture data sends however, are the exception to this.
116 | They happen immediately upon calling, however this behavior will be changed so they
117 | are also queued into the drawbuffer in a future version.
118 |
119 | * By default gsKit's active drawbuffer is Oneshot.
120 |
121 | * You can specify some external libraries in Makefile.pref
122 | (just uncomment what you need)
123 |
124 | ## Community
125 |
126 | Links for discussion and chat are available
127 | [here](https://ps2dev.github.io/#community).
128 |
129 | ## Credits
130 |
131 | See `AUTHORS`.
132 |
--------------------------------------------------------------------------------
/STATUS:
--------------------------------------------------------------------------------
1 | # ____ ___ | / _____ _____
2 | # | __ | |___/ | |
3 | # |___| ___| | \ __|__ | gsKit Open Source Project.
4 | # ----------------------------------------------------------------------
5 | # Copyright 2004 - Chris "Neovanglist" Gilbert
6 | # Licenced under Academic Free License version 2.0
7 | # Review gsKit README & LICENSE files for further details.
8 |
9 | This is an overview of the current project status.
10 |
11 | This project has 7 major components:
12 |
13 | gsCore - Low level routines that are critical to gsKit operation, as well as the renderpipe.
14 | gsFont - Font handling, conversion, and printing routines.
15 | gsInit - GS initialization and configuration routines.
16 | gsMisc - Miscellaneous routines that do not fit anywhere else.
17 | gsPrimitive - Primitive creation, manipulation, and handling routines.
18 | gsTexture - Texture loading, manipulation, and handling routines.
19 | gsVU1 - VU1 renderpipe.
20 |
21 | dmaKit Components:
22 |
23 | dmaCore - Core DMA routines.
24 | dmaInit - DMA Initilization routines.
25 |
26 | ______________________________________________________________
27 | | Component | Comment | % |
28 | |--------------------------------------------------------------|
29 | | gsCore | Completed. | 100% |
30 | |--------------------------------------------------------------|
31 | | gsInit | Completed. | 100% |
32 | |--------------------------------------------------------------|
33 | | gsMisc | PAL/NTSC/DTV/VGA Work | 100% |
34 | |--------------------------------------------------------------|
35 | | gsPrimitive | Completed. | 100% |
36 | |--------------------------------------------------------------|
37 | | gsTexture | Completed. | 100% |
38 | |--------------------------------------------------------------|
39 | | gsFont | BMP, FNT, and FONTM Implimented. | 90% |
40 | |--------------------------------------------------------------|
41 | | gsVU1 | Not Started. | 0% |
42 | |--------------------------------------------------------------|
43 | | dmaCore | Completed. | 100% |
44 | |--------------------------------------------------------------|
45 | | dmaInit | Completed. | 100% |
46 | |--------------------------------------------------------------|
47 |
48 | Contributors: Please do not modify this file without letting the others
49 | know what's going on. Please document your changes in the
50 | ChangeLog instead.
51 |
52 | BUGS:
53 | * Scaling for DVD modes untested.
54 | * Reports of Mode StartX/StartY values off. Please e-mail me with ones that work for you.
55 | * JPG Support Crashes (jpgOpen (fileXioOpen) crashes in sample/textures).
56 | * Something really wrong happens with vsync when GSKIT_DEBUG enabled.
57 | * Font sample doesn't work (crashes with "not enough VRAM")
58 | * Almost all warnings fixed except of some unused variables and one maybe unitialized value.
59 |
60 |
--------------------------------------------------------------------------------
/ee/dma/include/dmaArrays.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // dmaArrays.h - Array definitions for dmaKit
10 | //
11 |
12 | #ifndef __DMA_ARRAYS_H
13 | #define __DMA_ARRAYS_H
14 |
15 | static u32 DMA_CHCR[10] = { 0x10008000, 0x10009000, 0x1000A000, 0x1000B000, \
16 | 0x1000B400, 0x1000C000, 0x1000C400, 0x1000C800, \
17 | 0x1000D000, 0x1000D400 };
18 |
19 | static u32 DMA_MADR[10] = { 0x10008010, 0x10009010, 0x1000A010, 0x1000B010, \
20 | 0x1000B410, 0x1000C010, 0x1000C410, 0x1000C810, \
21 | 0x1000D010, 0x1000D410 };
22 |
23 | static u32 DMA_SIZE[10] = { 0x10008020, 0x10009020, 0x00000000, 0x00000000, \
24 | 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
25 | 0x00000000, 0x00000000 };
26 |
27 | static u32 DMA_TADR[10] = { 0x10008030, 0x10009030, 0x1000A030, 0x00000000, \
28 | 0x1000B430, 0x00000000, 0x1000C430, 0x00000000, \
29 | 0x00000000, 0x1000D430 };
30 |
31 | static u32 DMA_ASR0[10] = { 0x10008040, 0x10009040, 0x1000A040, 0x00000000, \
32 | 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
33 | 0x00000000, 0x00000000 };
34 |
35 | static u32 DMA_ASR1[10] = { 0x10008050, 0x10009050, 0x1000A050, 0x00000000, \
36 | 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
37 | 0x00000000, 0x00000000 };
38 |
39 | static u32 DMA_SADR[10] = { 0x10008080, 0x10009080, 0x1000A080, 0x00000000, \
40 | 0x00000000, 0x00000000, 0x00000000, 0x00000000, \
41 | 0x1000D080, 0x1000D480 };
42 |
43 | static u32 DMA_QWC[10] = { 0x00000000, 0x00000000, 0x1000A020, 0x1000B020, \
44 | 0x1000B420, 0x1000C020, 0x1000C420, 0x1000C820, \
45 | 0x1000D020, 0x1000D420 };
46 |
47 | static u8 DMA_TAG_ENABLE[10] = { 1, 1, 0, 1, 1, 1 ,1 ,1, 1, 1 };
48 |
49 | static char* DMA_NAME[10] = { "VIF0", "VIF1", "GIF", "fromIPU", "toIPU", \
50 | "SIF0", "SIF1", "SIF2", "fromSPR", "toSPR" };
51 |
52 | static void* DMA_SPR = (void*)SPR_START;
53 |
54 | #endif /* __DMA_ARRAYS_H__ */
55 |
--------------------------------------------------------------------------------
/ee/dma/include/dmaCore.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // dmaCore.h - Header for dmaCore.c
10 | //
11 |
12 | #ifndef __DMACORE_H__
13 | #define __DMACORE_H__
14 |
15 | #include "dmaKit.h"
16 |
17 | #define DMA_SET_CHCR(DIR,MODE,ASP,TTE,TIE,STR,TAG) \
18 | (u32)((DIR) & 0x00000001) << 0 | (u32)((MODE) & 0x00000003) << 2 | \
19 | (u32)((ASP) & 0x00000003) << 4 | (u32)((TTE ) & 0x00000001) << 6 | \
20 | (u32)((TIE) & 0x00000001) << 7 | (u32)((STR ) & 0x00000001) << 8 | \
21 | (u32)((TAG) & 0x0000FFFF) << 16
22 |
23 | #define DMA_SET_MADR(A,B) \
24 | (u32)((A) & 0x7FFFFFFF) << 0 | \
25 | (u32)((B) & 0x00000001) << 31
26 |
27 | #define DMA_SET_TADR(A,B) \
28 | (u32)((A) & 0x7FFFFFFF) << 0 | \
29 | (u32)((B) & 0x00000001) << 31
30 |
31 | #define DMA_SET_ASR0(A,B) \
32 | (u32)((A) & 0x7FFFFFFF) << 0 | \
33 | (u32)((B) & 0x00000001) << 31
34 |
35 | #define DMA_SET_ASR1(A,B) \
36 | (u32)((A) & 0x7FFFFFFF) << 0 | \
37 | (u32)((B) & 0x00000001) << 31
38 |
39 | #define DMA_SET_SADR(A) \
40 | (u32)((A) & 0x00003FFF) << 0
41 |
42 | #define DMA_SET_SIZE(A) \
43 | (u32)((A) & 0x0000FFFF) << 0
44 |
45 | #define DMA_MAX_SIZE 0xFFFF
46 |
47 | #define DMA_REFE 0x0
48 | #define DMA_CNT 0x1
49 | #define DMA_NEXT 0x2
50 | #define DMA_REF 0x3
51 | #define DMA_REFS 0x4
52 | #define DMA_CALL 0x5
53 | #define DMA_RET 0x6
54 | #define DMA_END 0x7
55 |
56 | #define DMA_TAG(QWC,PCE,ID,IRQ,ADDR,SPR) ( \
57 | ((u64)(QWC) << 0) | ((u64)(PCE) << 26) | \
58 | ((u64)(ID) << 28) | ((u64)(IRQ) << 31) | \
59 | ((u64)(ADDR) << 32) | ((u64)(SPR) << 63))
60 |
61 | #ifdef __cplusplus
62 | extern "C" {
63 | #endif
64 |
65 |
66 | /// DMA Wait Routine
67 | /// This routine checks and waits for the DMAC to become free.
68 | /// The other routines in dmaKit use this to know when it's clear
69 | /// to send data over the DMAC.
70 | int dmaKit_wait(u16 channel, u32 timeout);
71 |
72 | /// DMA Fast Wait Routine
73 | /// This routine does the same as above, but using an accelerated
74 | /// EE instruction method rather than register polling.
75 | /// The channels argument takes a bitmask of the channels you want to wait for.
76 | void dmaKit_wait_fast(void);
77 |
78 | /// DMA Send Routine
79 | /// Standard DMA send routine.
80 | void dmaKit_send(u16 channel, void *data, u32 size);
81 |
82 | /// DMA UCAB Send Routine
83 | /// Similar to dmaKit_send, but for UCAB data pointers.
84 | void dmaKit_send_ucab(u16 channel, void *data, u32 size);
85 |
86 | /// DMA Scratchpad Send Routine
87 | /// Similar to dmaKit_send, but reads from the scratchpad instead.
88 | void dmaKit_send_spr(u16 channel, void *data, u32 size);
89 |
90 | /// DMA Chain Send Routine
91 | /// Sends data over the DMAC using a DMA Chain.
92 | void dmaKit_send_chain(u16 channel, void *data, u32 size);
93 |
94 | /// DMA Chain UCAB Send
95 | /// Sends data which has been written to RAM using UCAB over the DMAC using a DMA Chain.
96 | void dmaKit_send_chain_ucab(u16 channel, void *data);
97 |
98 | /// DMA Chain Scratchpad Send
99 | /// Sends data over the DMAC using a DMA Chain via the scratchpad.
100 | void dmaKit_send_chain_spr(u16 channel, void *data);
101 |
102 | /// DMA Get from Scratchpad Routine
103 | /// Transfers data from an external source to the EE.
104 | /// (ex: Scratchpad -> EE Main Memory)
105 | void dmaKit_get_spr(u16 channel, void *data, void *dest, u32 size);
106 |
107 | #ifdef __cplusplus
108 | }
109 | #endif
110 |
111 | #endif /* __DMACORE_H__ */
112 |
--------------------------------------------------------------------------------
/ee/dma/include/dmaInit.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // dmaInit.h - Header for dmaInit.c
10 | //
11 | // Portions taken from ooPo's tutorial at:
12 | // http://www.oopo.net/consoledev/files/ps2-using-the-dmac.txt
13 | //
14 |
15 | #ifndef __DMAINIT_H__
16 | #define __DMAINIT_H__
17 |
18 | #include "dmaKit.h"
19 |
20 | #define D_CTRL_RELE_OFF 0x0
21 | #define D_CTRL_RELE_ON 0x1
22 |
23 | #define D_CTRL_MFD_OFF 0x0
24 | #define D_CTRL_MFD_RES 0x1
25 | #define D_CTRL_MFD_VIF 0x2
26 | #define D_CTRL_MFD_GIF 0x3
27 |
28 | #define D_CTRL_STS_UNSPEC 0x0
29 | #define D_CTRL_STS_SIF 0x1
30 | #define D_CTRL_STS_SPR 0x2
31 | #define D_CTRL_STS_IPU 0x3
32 |
33 | #define D_CTRL_STD_OFF 0x0
34 | #define D_CTRL_STD_VIF 0x1
35 | #define D_CTRL_STD_GIF 0x2
36 | #define D_CTRL_STD_SIF 0x3
37 |
38 | #define D_CTRL_RCYC_8 0x0
39 | #define D_CTRL_RCYC_16 0x1
40 | #define D_CTRL_RCYC_32 0x2
41 | #define D_CTRL_RCYC_64 0x3
42 | #define D_CTRL_RCYC_128 0x4
43 | #define D_CTRL_RCYC_256 0x5
44 |
45 | #define DMA_REG_CTRL (volatile u32 *)0x1000E000
46 | #define DMA_REG_STAT (volatile u32 *)0x1000E010
47 | #define DMA_REG_PCR (volatile u32 *)0x1000E020
48 | #define DMA_REG_SQWC (volatile u32 *)0x1000E030
49 | #define DMA_REG_RBSR (volatile u32 *)0x1000E040
50 | #define DMA_REG_RBOR (volatile u32 *)0x1000E050
51 |
52 | #define DMA_SET_CIS(A) *DMA_REG_STAT = (u32)(A)
53 | #define DMA_SET_CIM(A) *DMA_REG_STAT = (u32)((A) << 16)
54 | #define DMA_SET_CPCOND(A) *DMA_REG_PCR = (u32)(A)
55 |
56 | #define DMA_CHANNEL_VIF0 0x0
57 | #define DMA_CHANNEL_VIF1 0x1
58 | #define DMA_CHANNEL_GIF 0x2
59 | #define DMA_CHANNEL_FROMIPU 0x3
60 | #define DMA_CHANNEL_TOIPU 0x4
61 | #define DMA_CHANNEL_SIF0 0x5
62 | #define DMA_CHANNEL_SIF1 0x6
63 | #define DMA_CHANNEL_SIF2 0x7
64 | #define DMA_CHANNEL_FROMSPR 0x8
65 | #define DMA_CHANNEL_TOSPR 0x9
66 |
67 | #define DMA_SET_CTRL(A,B,C,D,E,F) \
68 | (u32)(A & 0x00000001) << 0 | (u32)(B & 0x00000001) << 1 | \
69 | (u32)(C & 0x00000003) << 2 | (u32)(D & 0x00000003) << 4 | \
70 | (u32)(E & 0x00000003) << 6 | (u32)(F & 0x00000007) << 8
71 |
72 | #ifdef __cplusplus
73 | extern "C" {
74 | #endif
75 |
76 | /// DMAC Initilization
77 | int dmaKit_init(u32 RELE, u32 MFD, u32 STS,
78 | u32 STD, u32 RCYC, u16 fastwaitchannels);
79 |
80 | /// DMA Channel Initilization
81 | int dmaKit_chan_init(u32 channel);
82 |
83 | #ifdef __cplusplus
84 | }
85 | #endif
86 |
87 | #endif /* __DMAINIT_H__ */
88 |
--------------------------------------------------------------------------------
/ee/dma/include/dmaKit.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // dmaKit.h - Master header for dmaKit. Include _ONLY_THIS_HEADER_
10 | // for gsKit. (Do NOT include dmacore.h, etc)
11 | //
12 | // Parts taken from ooPo's dmac tutorial.
13 | //
14 |
15 | #ifndef __DMAKIT_H__
16 | #define __DMAKIT_H__
17 |
18 | #include
19 |
20 | #include "dmaCore.h"
21 | #include "dmaInit.h"
22 | #include "dmaSpr.h"
23 |
24 | #endif /* __DMAKIT_H__ */
25 |
--------------------------------------------------------------------------------
/ee/dma/include/dmaSpr.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // dmaSpr.h - Header for dmaSpr.c
10 | // Parts taken from emoon's BreakPoint Demo Library
11 | //
12 |
13 | #ifndef __DMASPR_H__
14 | #define __DMASPR_H__
15 |
16 | #include "dmaKit.h"
17 |
18 | #define SPR_START 0x70000000
19 |
20 | #ifdef __cplusplus
21 | extern "C" {
22 | #endif
23 |
24 | /// DMA Scratchpad Chain Begin
25 | void *dmaKit_spr_begin(void);
26 |
27 | /// DMA Scratchpad Chain End
28 | int dmaKit_spr_end(void *data, void *StorePtr);
29 |
30 | /// DMA Scratchpad Allocation
31 | void *dmaKit_spr_alloc(int size);
32 |
33 | #ifdef __cplusplus
34 | }
35 | #endif
36 |
37 | #endif /* __DMASPR_H__ */
38 |
--------------------------------------------------------------------------------
/ee/dma/src/dmaCore.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // dmaCore.c - Core DMA Routines.
10 | // Parts taken from emoon's BreakPoint Demo Library
11 | //
12 |
13 | #include "dmaKit.h"
14 | #include "dmaArrays.h"
15 |
16 | #include
17 | #include
18 |
19 | #ifdef F_dmaKit_wait
20 | int dmaKit_wait(u16 channel, u32 timeout)
21 | {
22 | #ifdef GSKIT_DEBUG
23 | printf("Waiting for DMA Channel %i - %s\n",channel, DMA_NAME[channel]);
24 | #endif
25 |
26 | while((*(volatile u32 *)DMA_CHCR[channel]) & 0x00000100)
27 | {
28 | if( timeout != 0)
29 | {
30 | if ( timeout == 1 )
31 | {
32 | printf("Timed out waiting for DMA Channel %i - %s to be clear.\n",channel, DMA_NAME[channel]);
33 | return -1;
34 | }
35 | timeout--;
36 | }
37 | }
38 |
39 | #ifdef GSKIT_DEBUG
40 | printf("DMA Channel %i - %s is now clear.\n",channel, DMA_NAME[channel]);
41 | #endif
42 |
43 | return 0;
44 | }
45 | #endif
46 |
47 | #ifdef F_dmaKit_wait_fast
48 | void dmaKit_wait_fast(void)
49 | {
50 | asm __volatile__("sync.l; sync.p;" \
51 | "0:" \
52 | "bc0t 0f; nop;" \
53 | "bc0t 0f; nop;" \
54 | "bc0t 0f; nop;" \
55 | "bc0f 0b; nop;" \
56 | "0:");
57 | }
58 | #endif
59 |
60 | #ifdef F_dmaKit_send
61 | void dmaKit_send(u16 channel, void *data, u32 size)
62 | {
63 | #ifdef GSKIT_DEBUG
64 | printf("Sending to DMA Channel %i - %s\n",channel, DMA_NAME[channel]);
65 | #endif
66 |
67 | DMA_SET_CIS(1 << channel);
68 |
69 | SyncDCache(data, (void *)(((u8 *)data)+size*16));
70 |
71 | if(DMA_QWC[channel])
72 | *(volatile u32 *)DMA_QWC[channel] = size;
73 | *(volatile u32 *)DMA_MADR[channel] = DMA_SET_MADR((u32)data, 0);
74 | *(volatile u32 *)DMA_CHCR[channel] = DMA_SET_CHCR(1, // Direction
75 | 0, // ChainMode
76 | 0, // Address Stack Pointer
77 | DMA_TAG_ENABLE[channel], // Transfer DMA Tag
78 | 0, // Enable Interrupts
79 | 1, // Start DMA
80 | 0 ); // Priority Control Enable??
81 |
82 | #ifdef GSKIT_DEBUG
83 | printf("Sent to DMA Channel\n");
84 | #endif
85 |
86 | return;
87 | }
88 | #endif
89 |
90 | #ifdef F_dmaKit_send_ucab
91 | void dmaKit_send_ucab(u16 channel, void *data, u32 size)
92 | {
93 | #ifdef GSKIT_DEBUG
94 | printf("Sending to DMA Channel %i - %s\n",channel, DMA_NAME[channel]);
95 | #endif
96 |
97 | DMA_SET_CIS(1 << channel);
98 |
99 | if(DMA_QWC[channel])
100 | *(volatile u32 *)DMA_QWC[channel] = size;
101 | *(volatile u32 *)DMA_MADR[channel] = DMA_SET_MADR((u32)data - 0x30000000, 0);
102 | *(volatile u32 *)DMA_CHCR[channel] = DMA_SET_CHCR(1, // Direction
103 | 0, // ChainMode
104 | 0, // Address Stack Pointer
105 | DMA_TAG_ENABLE[channel], // Transfer DMA Tag
106 | 0, // Enable Interrupts
107 | 1, // Start DMA
108 | 0 ); // Priority Control Enable??
109 |
110 | #ifdef GSKIT_DEBUG
111 | printf("Sent to DMA Channel\n");
112 | #endif
113 |
114 | return;
115 | }
116 | #endif
117 |
118 | #ifdef F_dmaKit_send_spr
119 | void dmaKit_send_spr(u16 channel, void *data, u32 size)
120 | {
121 | #ifdef GSKIT_DEBUG
122 | printf("Sending to DMA Channel w/ SPR %i - %s\n",channel, DMA_NAME[channel]);
123 | #endif
124 |
125 | DMA_SET_CIS(1 << channel);
126 |
127 | if(DMA_QWC[channel])
128 | *(volatile u32 *)DMA_QWC[channel] = size;
129 | *(volatile u32 *)DMA_MADR[channel] = DMA_SET_MADR((u32)data, 1);
130 | *(volatile u32 *)DMA_CHCR[channel] = DMA_SET_CHCR(1, // Direction
131 | 0, // ChainMode
132 | 0, // Address Stack Pointer
133 | DMA_TAG_ENABLE[channel], // Transfer DMA Tag
134 | 0, // Enable Interrupts
135 | 1, // Start DMA
136 | 0 ); // Priority Control Enable??
137 | #ifdef GSKIT_DEBUG
138 | printf("Sent to DMA Channel w/ SPR\n");
139 | #endif
140 |
141 | return;
142 | }
143 | #endif
144 |
145 | #ifdef F_dmaKit_send_chain
146 | void dmaKit_send_chain(u16 channel, void *data, u32 size)
147 | {
148 | #ifdef GSKIT_DEBUG
149 | printf("Sending to DMA Channel in Chain Mode %i - %s\n",channel, DMA_NAME[channel]);
150 | #endif
151 |
152 | DMA_SET_CIS(1 << channel);
153 |
154 | SyncDCache(data, data+size*16);
155 |
156 | if(DMA_QWC[channel])
157 | *(volatile u32 *)DMA_QWC[channel] = 0;
158 |
159 | *(volatile u32 *)DMA_TADR[channel] = DMA_SET_TADR((u32)data, 0);
160 | *(volatile u32 *)DMA_CHCR[channel] = DMA_SET_CHCR(1, // Direction
161 | 1, // ChainMode
162 | 0, // Address Stack Pointer
163 | DMA_TAG_ENABLE[channel], // Transfer DMA Tag
164 | 0, // Enable Interrupts
165 | 1, // Start DMA
166 | 0 ); // Priority Control Enable??
167 |
168 | #ifdef GSKIT_DEBUG
169 | printf("Sent to DMA Channel in Chain Mode\n");
170 | #endif
171 | return;
172 | }
173 | #endif
174 |
175 | #ifdef F_dmaKit_send_chain_ucab
176 | void dmaKit_send_chain_ucab(u16 channel, void *data)
177 | {
178 | #ifdef GSKIT_DEBUG
179 | printf("Sending to DMA Channel in Chain Mode from UCAB %i - %s\n",channel, DMA_NAME[channel]);
180 | #endif
181 |
182 | DMA_SET_CIS(1 << channel);
183 |
184 | if(DMA_QWC[channel])
185 | *(volatile u32 *)DMA_QWC[channel] = 0;
186 |
187 | *(volatile u32 *)DMA_TADR[channel] = DMA_SET_TADR((u32)data - 0x30000000, 0);
188 | *(volatile u32 *)DMA_CHCR[channel] = DMA_SET_CHCR(1, // Direction
189 | 1, // ChainMode
190 | 0, // Address Stack Pointer
191 | DMA_TAG_ENABLE[channel], // Transfer DMA Tag
192 | 0, // Enable Interrupts
193 | 1, // Start DMA
194 | 0 ); // Priority Control Enable??
195 |
196 | #ifdef GSKIT_DEBUG
197 | printf("Sent to DMA Channel in Chain Mode from UCAB\n");
198 | #endif
199 | return;
200 | }
201 | #endif
202 |
203 | #ifdef F_dmaKit_send_chain_ucab
204 | void dmaKit_send_chain_spr(u16 channel, void *data)
205 | {
206 | #ifdef GSKIT_DEBUG
207 | printf("Sending to DMA Channel in Chain Mode w/Scratchpad %i - %s\n",channel, DMA_NAME[channel]);
208 | #endif
209 |
210 | DMA_SET_CIS(1 << channel);
211 |
212 | if(DMA_QWC[channel])
213 | *(volatile u32 *)DMA_QWC[channel] = 0;
214 | *(volatile u32 *)DMA_TADR[channel] = DMA_SET_TADR((u32)data, 1);
215 | *(volatile u32 *)DMA_CHCR[channel] = DMA_SET_CHCR(1, // Direction
216 | 1, // ChainMode
217 | 0, // Address Stack Pointer
218 | DMA_TAG_ENABLE[channel], // Transfer DMA Tag
219 | 0, // Enable Interrupts
220 | 1, // Start DMA
221 | 0 ); // Priority Control Enable??
222 |
223 | #ifdef GSKIT_DEBUG
224 | printf("Sent to DMA Channel in Chain Mode w/Scratchpad\n");
225 | #endif
226 | return;
227 | }
228 | #endif
229 |
230 | #ifdef F_dmaKit_get_spr
231 | void dmaKit_get_spr(u16 channel, void *data, void *dest, u32 size)
232 | {
233 | #ifdef GSKIT_DEBUG
234 | printf("Sending to DMA Channel %i - %s\n",channel, DMA_NAME[channel]);
235 | #endif
236 |
237 | DMA_SET_CIS(1 << channel);
238 |
239 | if(DMA_QWC[channel])
240 | *(volatile u32 *)DMA_QWC[channel] = size;
241 |
242 | *(volatile u32 *)DMA_SADR[channel] = DMA_SET_SADR((u32)data&0x3fff);
243 | *(volatile u32 *)DMA_MADR[channel] = DMA_SET_MADR((u32)dest&0x0fffffff, 0);
244 | *(volatile u32 *)DMA_CHCR[channel] = DMA_SET_CHCR(0, // Direction
245 | 0, // ChainMode
246 | 0, // Address Stack Pointer
247 | DMA_TAG_ENABLE[channel], // Transfer DMA Tag
248 | 0, // Enable Interrupts
249 | 1, // Start DMA
250 | 0 ); // Priority Control Enable??
251 |
252 | #ifdef GSKIT_DEBUG
253 | printf("Sent to DMA Channel\n");
254 | #endif
255 |
256 | return;
257 | }
258 | #endif
259 |
260 |
--------------------------------------------------------------------------------
/ee/dma/src/dmaInit.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // dmaInit.c - DMA initilization routines.
10 | //
11 |
12 | #include "dmaKit.h"
13 | #include "dmaArrays.h"
14 |
15 | #include
16 | #include
17 |
18 | #if F_dmaKit_init
19 | int dmaKit_init(u32 RELE, u32 MFD, u32 STS,
20 | u32 STD, u32 RCYC, u16 fastwaitchannels)
21 | {
22 | #ifdef GSKIT_DEBUG
23 | printf("Initializing the DMAC: RELE=%i MFD=%i STS=%i STD=%i RCYC=%i\n",
24 | RELE, MFD, STS, STD, RCYC);
25 | #endif
26 |
27 | *DMA_REG_CTRL = 0x00000000;
28 | *DMA_REG_PCR = 0x00000000;
29 | *DMA_REG_SQWC = 0x00000000;
30 | *DMA_REG_RBSR = 0x00000000;
31 | *DMA_REG_RBOR = 0x00000000;
32 |
33 | *DMA_REG_CTRL = DMA_SET_CTRL(1, RELE, MFD, STS, STD, RCYC);
34 |
35 | DMA_SET_CPCOND(fastwaitchannels);
36 |
37 | #ifdef GSKIT_DEBUG
38 | printf("DMAC Initialized.\n");
39 | #endif
40 |
41 | return 0;
42 | }
43 | #endif
44 |
45 | #if F_dmaKit_chan_init
46 | int dmaKit_chan_init(u32 channel)
47 | {
48 | if(channel >= 0 && channel <= 9)
49 | {
50 | #ifdef GSKIT_DEBUG
51 | printf("Initilizating DMA Channel %i - %s\n",channel, DMA_NAME[channel]);
52 | #endif
53 |
54 | *(volatile u32 *)DMA_CHCR[channel] = 0x00000000;
55 | *(volatile u32 *)DMA_MADR[channel] = 0x00000000;
56 | if(DMA_SIZE[channel] > 0)
57 | *(volatile u32 *)DMA_SIZE[channel] = 0x00000000;
58 | if(DMA_TADR[channel] > 0)
59 | *(volatile u32 *)DMA_TADR[channel] = 0x00000000;
60 | if(DMA_ASR0[channel] > 0)
61 | *(volatile u32 *)DMA_ASR0[channel] = 0x00000000;
62 | if(DMA_ASR1[channel] > 0)
63 | *(volatile u32 *)DMA_ASR1[channel] = 0x00000000;
64 | if(DMA_SADR[channel] > 0)
65 | *(volatile u32 *)DMA_SADR[channel] = 0x00000000;
66 | if(DMA_QWC[channel] > 0)
67 | *(volatile u32 *)DMA_QWC[channel] = 0x00000000;
68 | }
69 | else
70 | {
71 | printf("Invalid DMA Channel Specified: %i\n",channel);
72 | printf("Failed to Initialize DMA Channel.\n");
73 | return -1;
74 | }
75 |
76 | #ifdef GSKIT_DEBUG
77 | printf("DMA Channel Initialized.\n");
78 | #endif
79 |
80 | return 0;
81 | }
82 | #endif
83 |
--------------------------------------------------------------------------------
/ee/dma/src/dmaSpr.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // dmaSpr.c - Interface to scratchpad.
10 | // Parts taken from emoon's BreakPoint Demo Library
11 | //
12 |
13 | #include "dmaKit.h"
14 | #include "kernel.h"
15 | #include "dmaArrays.h"
16 | #include
17 |
18 | #if F_dmaKit_spr_begin
19 | void *dmaKit_spr_begin(void)
20 | {
21 | #ifdef GSKIT_DEBUG
22 | printf("Begining Scratchpad Chain\n");
23 | #endif
24 | return (void *)dmaKit_spr_alloc(100 * 16);
25 | }
26 | #endif
27 |
28 | #if F_dmaKit_spr_end
29 | int dmaKit_spr_end(void *data, void *StorePtr)
30 | {
31 | int q_size;
32 | #ifdef GSKIT_DEBUG
33 | printf("Ending Scratchpad Chain\n");
34 | #endif
35 | q_size = (u32)data - (u32)StorePtr;
36 | return q_size >> 4;
37 | }
38 | #endif
39 |
40 | #if F_dmaKit_spr_alloc
41 | void *dmaKit_spr_alloc(int size)
42 | {
43 | void *p_spr = DMA_SPR;
44 | #ifdef GSKIT_DEBUG
45 | printf("Allocating Scratchpad Memory\n");
46 | #endif
47 | if( (u32)DMA_SPR + size >= 0x70004000)
48 | DMA_SPR = (void*)SPR_START;
49 |
50 | p_spr = DMA_SPR;
51 | DMA_SPR += size;
52 |
53 | #ifdef GSKIT_DEBUG
54 | printf("Scratchpad Memory Allocated\n");
55 | #endif
56 | return p_spr;
57 | }
58 | #endif
59 |
60 |
--------------------------------------------------------------------------------
/ee/gs/include/gsCore.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // gsCore.h - Header for gsCore.c
10 | //
11 | // Parts taken from emoon's BreakPoint Demo Library
12 | //
13 |
14 | #ifndef __GSCORE_H__
15 | #define __GSCORE_H__
16 |
17 | #include "gsKit.h"
18 |
19 | /// GS VRAM "System" Allocation (Framebuffer, ZBuffer, etc)
20 | #define GSKIT_ALLOC_SYSBUFFER 0x00
21 | /// GS VRAM "User" Allocation (Texture, CLUT, etc)
22 | #define GSKIT_ALLOC_USERBUFFER 0x01
23 |
24 | /// Return this is VRAM allocation fails.
25 | #define GSKIT_ALLOC_ERROR 0x00
26 |
27 | /// GS GIF Data Transfer Blocksize
28 | #define GS_GIF_BLOCKSIZE 0x7fff
29 |
30 | /// VRAM Allcoate Blocksize (For System Buffers)(CRITICAL FOR VRAM ALIGNMENT)
31 | #define GS_VRAM_BLOCKSIZE_8K 8192
32 | /// VRAM Allcoate Blocksize (For User Textures)(CRITICAL FOR VRAM ALIGNMENT)
33 | #define GS_VRAM_BLOCKSIZE_256 256
34 | /// Texture Base Width Allocation Allignment (32/24/16 Bit Textures)
35 | #define GS_VRAM_TBWALIGN 64
36 | /// Texture Base Width Allocation Allignment (8/4 Bit CLUT Textures)
37 | #define GS_VRAM_TBWALIGN_CLUT 128
38 |
39 | /// Repeats ("Tiles") Texture Across the Surface.
40 | #define GS_CMODE_REPEAT 0x00
41 | /// Stretches Texture Across the Surface
42 | #define GS_CMODE_CLAMP 0x01
43 | /// Stretches Texture Across the Region Defined by MINU, MAXU, MINV, and MAXV
44 | #define GS_CMODE_REGION_CLAMP 0x02
45 | /// Repeats a Portion of the Texture Defined by UMSK (MINU), VMSK (MINV), UFIX (MAXU), and VFIX (MAXV)
46 | #define GS_CMODE_REGION_REPEAT 0x03
47 | /// Resets CLAMP vales to whatever is in gsGlobal->Clamp
48 | #define GS_CMODE_RESET 0xFF
49 |
50 | /// Resets SCISSOR values to the entire display bounds
51 | #define GS_SCISSOR_RESET 0x00
52 |
53 | /// Turns off Z Testing
54 | #define GS_ZTEST_OFF 0x01
55 | /// Turns on Z Testing
56 | #define GS_ZTEST_ON 0x02
57 | /// Turns off Alpha Testing (Source)
58 | #define GS_ATEST_OFF 0x03
59 | /// Turns on Alpha Testing (Source)
60 | #define GS_ATEST_ON 0x04
61 | /// Turns off Alpha Testing (Destination)
62 | #define GS_D_ATEST_OFF 0x05
63 | /// Turns on Alpha Testing (Destination)
64 | #define GS_D_ATEST_ON 0x06
65 |
66 | /// Use simple filtering (nearest neighbor)
67 | #define GS_FILTER_NEAREST 0x00
68 | /// Use bilinear filter on texture
69 | #define GS_FILTER_LINEAR 0x01
70 |
71 | /// Use clut storage mode CSM1
72 | #define GS_CLUT_STORAGE_CSM1 0x00
73 | /// Use clut storage mode CSM2
74 | #define GS_CLUT_STORAGE_CSM2 0x01
75 |
76 | /// Basic X/Y/Z Vertex Structure
77 | struct gsVertex
78 | {
79 | s32 x __attribute__ ((packed));
80 | s32 y __attribute__ ((packed));
81 | s32 z __attribute__ ((packed));
82 | };
83 | typedef struct gsVertex GSVERTEX;
84 |
85 | #ifdef __cplusplus
86 | extern "C" {
87 | #endif
88 |
89 | /// GS VRAM Allocation
90 | u32 gsKit_vram_alloc(GSGLOBAL *gsGlobal, u32 size, u8 type);
91 |
92 | /// GS VRAM Clear
93 | void gsKit_vram_clear(GSGLOBAL *gsGlobal);
94 |
95 | /// Flips Framebuffers on VSync
96 | /// This calls gsKit_vsync_wait, then calls gsKit_setactive
97 | /// to swap your framebuffers.
98 | ///
99 | /// It then sets your active PrimContext and ActiveBuffer
100 | /// appropriately.
101 | void gsKit_sync_flip(GSGLOBAL *gsGlobal);
102 |
103 | /// Sets the LockBuffer parameter of gsGlobal to GS_SETTING_ON
104 | /// Used with gsKit_unlock_buffer and gsKit_lock_status
105 | /// This enables you to lock your current working buffer so it isn't
106 | /// flipped while it's being worked on
107 | void gsKit_lock_buffer(GSGLOBAL *gsGlobal);
108 |
109 | /// Sets the LockBuffer parameter of gsGlobal to GS_SETTING_OFF
110 | /// Used with gsKit_unlock_buffer and gsKit_lock_status
111 | /// This enables you to unlock your current working buffer so it can
112 | /// be flipped
113 | void gsKit_unlock_buffer(GSGLOBAL *gsGlobal);
114 |
115 | /// Returns the status of LockBuffer parameter of gsGlobal
116 | /// If it returns GS_SETTING_ON then the buffer is locked
117 | /// If it returns GS_SETTING_OFF then the buffer is unlocked
118 | int gsKit_lock_status(GSGLOBAL *gsGlobal);
119 |
120 | /// Switches the currently displayed buffer for the current
121 | /// working buffer or front buffer with back buffer
122 | void gsKit_display_buffer(GSGLOBAL *gsGlobal);
123 |
124 | /// Switches the current working buffer with the
125 | /// last displayed buffer or back buffer with front buffer
126 | void gsKit_switch_context(GSGLOBAL *gsGlobal);
127 |
128 | /// Sets Your Active Framebuffer
129 | void gsKit_setactive(GSGLOBAL *gsGlobal);
130 |
131 | /// Blocks until FINISH is triggered
132 | void gsKit_finish(void);
133 |
134 | /// Blocks Until a VSync
135 | void gsKit_vsync_wait(void);
136 |
137 | /// Blocks until a HSync
138 | void gsKit_hsync_wait(void);
139 |
140 | /// Initiates a vsync but doesn't block
141 | void gsKit_vsync_nowait(void);
142 |
143 | /// Installs a vsync interrupt handler (vblank_start)
144 | int gsKit_add_vsync_handler(int (*vsync_callback)(int));
145 |
146 | /// Removes a vsync interrupt handler
147 | void gsKit_remove_vsync_handler(int callback_id);
148 |
149 | /// Installs a hsync interrupt handler (hblank_start)
150 | int gsKit_add_hsync_handler(int (*hsync_callback)(int));
151 |
152 | /// Removes a hsync interrupt handler
153 | void gsKit_remove_hsync_handler(int callback_id);
154 |
155 | /// Installs a finish interrupt handler
156 | int gsKit_add_finish_handler(int (*finish_callback)(int));
157 |
158 | /// Removes a finish interrupt handler
159 | void gsKit_remove_finish_handler(int callback_id);
160 |
161 | /// Sets gsGlobal->EvenOrOdd depending on current field drawing
162 | void gsKit_get_field(GSGLOBAL *gsGlobal);
163 |
164 | /// Sets the GS to draw only on even/odd/both fields (from libgraph)
165 | void gsKit_set_drawfield(GSGLOBAL *gsGlobal, u8 field);
166 |
167 | /// Clears the Screen With the Specified Color
168 | /// This actually just momentarily turns off Z Test,
169 | /// then draws a sprite with the given color at a Z depth of 0.
170 | /// It then restores whatever your previous Z Test settings were.
171 | void gsKit_clear(GSGLOBAL *gsGlobal, u64 Color);
172 |
173 | /// Sets the SCISSOR Parameters
174 | ///
175 | /// GS_SCISSOR_RESET resets scissor box to the entire display;
176 | /// otherwise, GS_SETREG_SCISSOR() provides a specific box.
177 | void gsKit_set_scissor(GSGLOBAL *gsGlobal, u64 ScissorBounds);
178 |
179 | /// Sets the TEST Parameters
180 | /// This manipulates the TEST struture of gsGlobal according to
181 | /// the Preset value. It then sends the new TEST parameters to the GS
182 | /// to put it into effect.
183 | ///
184 | /// Valid Presets Are:
185 | ///
186 | /// GS_ZTEST_OFF - Turns off Z Testing
187 | ///
188 | /// GS_ZTEST_ON - Turns on Z Testing
189 | ///
190 | /// GS_ATEST_OFF - Turns off Alpha Testing (Source)
191 | ///
192 | /// GS_ATEST_ON - Turns on Alpha Testing (Source)
193 | ///
194 | /// GS_D_ATEST_OFF - Turns off Alpha Testing (Destination)
195 | ///
196 | /// GS_D_ATEST_ON - Turns on Alpha Testing (Destination)
197 | void gsKit_set_test(GSGLOBAL *gsGlobal, u8 Preset);
198 |
199 | /// Sets the CLAMP Parameters
200 | /// This manipulates the CLAMP struture of gsGlobal according to
201 | /// the Preset value. It then sends the new CLAMP parameters to the GS
202 | /// to put it into effect.
203 | ///
204 | /// Valid Presets Are:
205 | ///
206 | /// GS_CMODE_REPEAT - Repeats ("Tiles") Texture Across the Surface.
207 | ///
208 | /// GS_CMODE_CLAMP - Stretches Texture Across the Surface
209 | ///
210 | /// GS_CMODE_REGION_REPEAT - Stretches Texture Across the Region Defined
211 | /// by MINU, MAXU, MINV, and MAXV
212 | ///
213 | /// GS_CMODE_REGION_CLAMP - Repeats a Portion of the Texture Defined by
214 | /// UMSK (MINU), VMSK (MINV), UFIX (MAXU), and VFIX (MAXV)
215 | void gsKit_set_clamp(GSGLOBAL *gsGlobal, u8 Preset);
216 |
217 | /// Sets the Alpha Blending Parameters
218 | void gsKit_set_primalpha(GSGLOBAL *gsGlobal, u64 AlphaMode, u8 PerPixel);
219 |
220 | /// Sets the Texture Filtering Parameters
221 | void gsKit_set_texfilter(GSGLOBAL *gsGlobal, u8 FilterMode);
222 |
223 | /// Sets the CLUT position specfications
224 | void gsKit_set_texclut(GSGLOBAL *gsGlobal, gs_texclut texClut);
225 |
226 | /// Sets the Dither Matrix Setting
227 | void gsKit_set_dither_matrix(GSGLOBAL *gsGlobal);
228 |
229 | /// Enables/Disables dithering, with the gsGlobal Dithering option.
230 | void gsKit_set_dither(GSGLOBAL *gsGlobal);
231 |
232 | /// Append the Current Queue with a GS_FINISH Register
233 | GSQUEUE gsKit_set_finish(GSGLOBAL *gsGlobal);
234 |
235 | /// Reset specified drawqueue to it's initial state (Useful for clearing the Persistent Queue)
236 | void gsKit_queue_reset(GSQUEUE *Queue);
237 |
238 | /// Normal User Draw Queue "Execution" (Kicks Oneshot and Persistent Queues)
239 | void gsKit_queue_exec(GSGLOBAL *gsGlobal);
240 |
241 | /// Specific Draw Queue "Execution" (Kicks the Queue passed for the second argument)
242 | void gsKit_queue_exec_real(GSGLOBAL *gsGlobal, GSQUEUE *Queue);
243 |
244 | /// Allocate UCAB buffer in GSQUEUE, internal use only
245 | void *gsKit_alloc_ucab(int size);
246 |
247 | /// Free UCAB buffer in GSQUEUE, internal use only
248 | void gsKit_free_ucab(void *p);
249 |
250 | /// Initialize a Draw Queue (Allocates memory for the Queue)
251 | void gsKit_queue_init(GSGLOBAL *gsGlobal, GSQUEUE *Queue, u8 mode, int size);
252 |
253 | /// Free Allocated Memory for Draw Queue
254 | void gsKit_queue_free(GSGLOBAL *gsGlobal, GSQUEUE *Queue);
255 |
256 | /// Set Current Draw Queue
257 | void gsKit_queue_set(GSGLOBAL *gsGlobal, GSQUEUE *Queue);
258 |
259 | /// Set Current Draw Queue (Between GS_ONESHOT and GS_PERSISTENT)
260 | void gsKit_mode_switch(GSGLOBAL *gsGlobal, u8 mode);
261 |
262 | #ifdef __cplusplus
263 | }
264 | #endif
265 |
266 | #endif /* __GSCORE_H__ */
267 |
--------------------------------------------------------------------------------
/ee/gs/include/gsFontM.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // gsFontM.h - Header for gsFontM.c
10 | //
11 |
12 | #ifndef __GSFONTM_H__
13 | #define __GSFONTM_H__
14 |
15 | #include "gsKit.h"
16 |
17 | #define GSKIT_FONTM_MAXLINES 255
18 |
19 | #define GSKIT_FALIGN_LEFT 0x00
20 | #define GSKIT_FALIGN_CENTER 0x01
21 | #define GSKIT_FALIGN_RIGHT 0x02
22 |
23 | #define ALPHA_SRC 0
24 | #define ALPHA_DST 1
25 | #define ALPHA_ZERO 2
26 | #define ALPHA_FIX 2
27 | #define ALPHA(A,B,C,D,FIX) ( (((u64)(A))&3) | ((((u64)(B))&3)<<2) | ((((u64)(C))&3)<<4) | ((((u64)(D))&3)<<6) | ((((u64)(FIX)))<<32UL) )//(A - B)*C >> 7 + D
28 |
29 | #define ALPHA_BLEND_NORMAL (ALPHA(ALPHA_SRC,ALPHA_DST,ALPHA_SRC,ALPHA_DST,0x00))
30 | #define ALPHA_BLEND_ADD_NOALPHA (ALPHA(ALPHA_SRC,ALPHA_ZERO,ALPHA_FIX,ALPHA_DST,0x80))
31 | #define ALPHA_BLEND_ADD (ALPHA(ALPHA_SRC,ALPHA_ZERO,ALPHA_SRC,ALPHA_DST,0x00))
32 |
33 | #define GS_FONTM_PAGE_COUNT 8
34 |
35 | struct gsKit_fontm_unpack
36 | {
37 | u32 size;
38 | u32 data;
39 | u32 ande;
40 | u32 dif;
41 | u32 shft;
42 | u8 *ptr;
43 | };
44 |
45 | /// gsKit FONTM Header Structure
46 | /// This stores the vital data for unpacked FONTM glyphsets.
47 | struct gsKit_fontm_header
48 | {
49 | u32 sig;
50 | u32 version;
51 | u32 bitsize;
52 | u32 baseoffset;
53 | u32 num_entries;
54 | u32 eof;
55 | u32 *offset_table;
56 | };
57 | typedef struct gsKit_fontm_header GSFONTMHDR;
58 |
59 | /// gsKit Font Structure
60 | /// This structure holds all relevant data for any
61 | /// given font object, regardless of original format or type.
62 | struct gsFontM
63 | {
64 | GSTEXTURE *Texture[GS_FONTM_PAGE_COUNT]; ///< Font Texture Objects
65 | GSFONTMHDR Header; ///< FONTM Header
66 | u32 VramIdx; ///< FONTM Current Double Buffer Index
67 | u8 Align; ///< FONTM Line Alignment
68 | float Spacing; ///< FONTM Glyph Spacing
69 | void *TexBase; ///< Glyphs Texture Base
70 | };
71 | typedef struct gsFontM GSFONTM;
72 |
73 |
74 | #ifdef __cplusplus
75 | extern "C" {
76 | #endif
77 |
78 | /// Create Font Object
79 | GSFONTM *gsKit_init_fontm();
80 | /// Free Font Object
81 | void gsKit_free_fontm(GSGLOBAL *gsGlobal, GSFONTM *gsFontM);
82 |
83 | int gsKit_fontm_upload(GSGLOBAL *gsGlobal, GSFONTM *gsFontM);
84 | int gsKit_fontm_unpack(GSFONTM *gsFontM);
85 | void gsKit_fontm_unpack_raw(u8 *base, struct gsKit_fontm_unpack *oke);
86 | void gsKit_fontm_unpack_raw_1(struct gsKit_fontm_unpack *oke);
87 | void gsKit_fontm_print_scaled(GSGLOBAL *gsGlobal, GSFONTM *gsFontM, float X, float Y, int Z,
88 | float scale, unsigned long color, const char *String);
89 |
90 | #define gsKit_fontm_print(gsGlobal, gsFontM, X, Y, Z, color, String) \
91 | gsKit_fontm_print_scaled(gsGlobal, gsFontM, X, Y, Z, 1.0f, color, String);
92 |
93 | #ifdef __cplusplus
94 | }
95 | #endif
96 |
97 | #endif /* __GSFONT_H__ */
98 |
--------------------------------------------------------------------------------
/ee/gs/include/gsHires.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2017 - Rick "Maximus32" Gaiser
6 | // Copyright 2004 - Chris "Neovanglist" Gilbert
7 | // Licenced under Academic Free License version 2.0
8 | // Review gsKit README & LICENSE files for further details.
9 | //
10 | // gsHires.h - Header for gsHires.c
11 | //
12 |
13 | #ifndef __GSHIRES_H__
14 | #define __GSHIRES_H__
15 |
16 |
17 | #include "gsKit.h"
18 |
19 |
20 | #ifdef __cplusplus
21 | extern "C" {
22 | #endif
23 |
24 |
25 | /// Wait for VSync
26 | void gsKit_hires_sync(GSGLOBAL *gsGlobal);
27 |
28 | /// Flips Draw Queue
29 | void gsKit_hires_flip(GSGLOBAL *gsGlobal);
30 |
31 | /// Converts PSM and interlacing for use as background image
32 | void gsKit_hires_prepare_bg(GSGLOBAL *gsGlobal, GSTEXTURE * tex);
33 |
34 | /// Set background texture, must be same size and PSM as display
35 | int gsKit_hires_set_bg(GSGLOBAL *gsGlobal, GSTEXTURE * tex);
36 |
37 | /// Initialize Screen and GS Registers, for multi pass high resolution mode
38 | void gsKit_hires_init_screen(GSGLOBAL *gsGlobal, int passCount);
39 |
40 | /// Initialize gsGlobal
41 | GSGLOBAL *gsKit_hires_init_global();
42 |
43 | /// De-initialize gsGlobal
44 | void gsKit_hires_deinit_global(GSGLOBAL *gsGlobal);
45 |
46 |
47 | #ifdef __cplusplus
48 | }
49 | #endif
50 |
51 |
52 | #endif /* __GSHIRES_H__ */
53 |
--------------------------------------------------------------------------------
/ee/gs/include/gsInline.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // gsInline.h - Static Inline Routines
10 | //
11 | //
12 |
13 | #ifndef __GSINLINE_H__
14 | #define __GSINLINE_H__
15 |
16 | #include
17 | #include
18 |
19 | // Drawbuffer Heap Allocator, GSQUEUE version
20 | static inline void *_gsKit_heap_alloc(GSQUEUE *q, int qsize, int bsize, int type)
21 | {
22 | void *p_heap;
23 |
24 | #ifdef GSKIT_DEBUG
25 | if(((u32)q->pool_cur + bsize ) >= (u32)q->pool_max[q->dbuf])
26 | {
27 | printf("GSKIT: WARNING! HEAP OVERFLOW FOR RENDERQUEUE %p!!\n", q);
28 | return NULL;
29 | }
30 | #endif
31 |
32 | if((q->tag_size + qsize) >= 65535)
33 | {
34 | *(u64 *)q->dma_tag = DMA_TAG(q->tag_size, 0, DMA_CNT, 0, 0, 0);
35 | q->tag_size = 0;
36 | q->dma_tag = q->pool_cur;
37 | q->pool_cur = (u8*)q->pool_cur + 16;
38 | }
39 |
40 | if(type == GIF_AD || type != q->last_type || q->same_obj >= GS_GIF_BLOCKSIZE)
41 | {
42 | if(q->last_type != GIF_RESERVED && q->last_type != GIF_AD)
43 | *(u64 *)q->last_tag = ((u64)q->same_obj | *(u64 *)q->last_tag);
44 |
45 | qsize ++;
46 | bsize += 16;
47 | q->last_tag = q->pool_cur;
48 | q->same_obj = 0;
49 | }
50 |
51 | q->same_obj++;
52 | q->last_type = type;
53 | q->tag_size += qsize;
54 | p_heap = q->pool_cur;
55 | q->pool_cur = (u8*)q->pool_cur + bsize;
56 |
57 | return p_heap;
58 | }
59 |
60 | /// Drawbuffer Heap Allocator
61 | static inline void *gsKit_heap_alloc(GSGLOBAL *gsGlobal, int qsize, int bsize, int type)
62 | {
63 | return _gsKit_heap_alloc(gsGlobal->CurQueue, qsize, bsize, type);
64 | }
65 |
66 | // Drawbuffer Heap Allocator (For Injected DMA_TAGs), GSQUEUE version
67 | static inline void *_gsKit_heap_alloc_dma(GSQUEUE *q, int qsize, int bsize)
68 | {
69 | void *p_heap;
70 |
71 | #ifdef GSKIT_DEBUG
72 | if(((u32)q->pool_cur + bsize ) >= (u32)q->pool_max[q->dbuf])
73 | {
74 | printf("GSKIT: WARNING! HEAP OVERFLOW FOR RENDERQUEUE %p!!\n", q);
75 | return NULL;
76 | }
77 | #endif
78 |
79 | if(q->last_type != GIF_RESERVED && q->last_type != GIF_AD)
80 | {
81 | *(u64 *)q->last_tag = ((u64)q->same_obj | *(u64 *)q->last_tag);
82 | }
83 |
84 | *(u64 *)q->dma_tag = DMA_TAG(q->tag_size, 0, DMA_CNT, 0, 0, 0);
85 | q->tag_size = 0;
86 |
87 | q->last_type = GIF_RESERVED;
88 | q->same_obj = 0;
89 |
90 | p_heap = q->pool_cur;
91 | q->pool_cur = (u8*)q->pool_cur + bsize;
92 | q->dma_tag = q->pool_cur;
93 | q->pool_cur = (u8*)q->pool_cur + 16;
94 |
95 | return p_heap;
96 | }
97 |
98 | /// Drawbuffer Heap Allocator (For Injected DMA_TAGs)
99 | static inline void *gsKit_heap_alloc_dma(GSGLOBAL *gsGlobal, int qsize, int bsize)
100 | {
101 | return _gsKit_heap_alloc_dma(gsGlobal->CurQueue, qsize, bsize);
102 | }
103 |
104 | static inline int __gsKit_float_to_int_uv(float fuv, int imax)
105 | {
106 | int iuv = (int)(fuv * 16.0f);
107 |
108 | // Limit u/v to texture width/height
109 |
110 | if (iuv < 0)
111 | iuv = 0;
112 |
113 | if (iuv > imax)
114 | iuv = imax;
115 |
116 | // Prevent overflow when using maximum size texture
117 |
118 | if (iuv >= (1024 * 16))
119 | iuv = (1024 * 16) - 1;
120 |
121 | return iuv;
122 | }
123 |
124 | static inline int gsKit_float_to_int_u(const GSTEXTURE *Texture, float fu)
125 | {
126 | return __gsKit_float_to_int_uv(fu, Texture->Width * 16);
127 | }
128 |
129 | static inline int gsKit_float_to_int_v(const GSTEXTURE *Texture, float fv)
130 | {
131 | return __gsKit_float_to_int_uv(fv, Texture->Height * 16);
132 | }
133 |
134 | static inline int __gsKit_float_to_int_xy(float fxy, int offset)
135 | {
136 | int ixy = (int)(fxy * 16.0f) + offset;
137 |
138 | // Limit x/y to Primitive Coordinate System (0 to 4095.9375)
139 |
140 | if (ixy < 0)
141 | ixy = 0;
142 |
143 | if (ixy >= (4096 * 16))
144 | ixy = (4096 * 16) - 1;
145 |
146 | return ixy;
147 | }
148 |
149 | static inline int gsKit_float_to_int_x(const GSGLOBAL *gsGlobal, float fx)
150 | {
151 | return __gsKit_float_to_int_xy(fx, gsGlobal->OffsetX);
152 | }
153 |
154 | static inline int gsKit_float_to_int_y(const GSGLOBAL *gsGlobal, float fy)
155 | {
156 | return __gsKit_float_to_int_xy(fy, gsGlobal->OffsetY);
157 | }
158 |
159 | static inline gs_xyz2 vertex_to_XYZ2(const GSGLOBAL *gsGlobal, float fx, float fy, int iz)
160 | {
161 | gs_xyz2 res;
162 |
163 | res.xyz.x = gsKit_float_to_int_x(gsGlobal, fx);
164 | res.xyz.y = gsKit_float_to_int_y(gsGlobal, fy);
165 | res.xyz.z = iz;
166 | res.tag = GS_XYZ2;
167 |
168 | return res;
169 | }
170 |
171 | // If STQ coordinates are used set q to 1.0f otherwise keep it as 0.0f
172 | static inline gs_rgbaq color_to_RGBAQ(uint8_t r, uint8_t g, uint8_t b, uint8_t a, float q)
173 | {
174 | gs_rgbaq res;
175 |
176 | res.color.components.r = r;
177 | res.color.components.g = g;
178 | res.color.components.b = b;
179 | res.color.components.a = a;
180 | res.color.q = q;
181 | res.tag = GS_RGBAQ;
182 |
183 | return res;
184 | }
185 |
186 | // If STQ coordinates are used set q to 1.0f otherwise keep it as 0.0f
187 | static inline gs_rgbaq rgba_to_RGBAQ(uint32_t rgba, float q)
188 | {
189 | gs_rgbaq res;
190 |
191 | res.color.components.rgba = rgba;
192 | res.color.q = q;
193 | res.tag = GS_RGBAQ;
194 |
195 | return res;
196 | }
197 |
198 | static inline gs_rgbaq rgbaq_to_RGBAQ(uint64_t rgbaq)
199 | {
200 | gs_rgbaq res;
201 |
202 | res.color.rgbaq = rgbaq;
203 | res.tag = GS_RGBAQ;
204 |
205 | return res;
206 | }
207 |
208 | static inline gs_uv vertex_to_UV(const GSTEXTURE *Texture, float u, float v)
209 | {
210 | gs_uv res;
211 |
212 | int iu = gsKit_float_to_int_u(Texture, u);
213 | int iv = gsKit_float_to_int_v(Texture, v);
214 |
215 | res.coord.u = iu;
216 | res.coord.v = iv;
217 | res.tag = GS_UV;
218 |
219 | return res;
220 | }
221 |
222 | static inline gs_stq vertex_to_STQ(float s, float t)
223 | {
224 | gs_stq res;
225 |
226 | res.st.s = s;
227 | res.st.t = t;
228 | res.tag = GS_ST;
229 |
230 | return res;
231 | }
232 |
233 | static inline gs_texclut postion_to_TEXCLUT(u8 cbw, u8 cou, u8 cov)
234 | {
235 | gs_texclut res;
236 |
237 | res.specification.cbw = cbw;
238 | res.specification.cou = cou;
239 | res.specification.cov = cov;
240 | res.tag = GS_TEXCLUT;
241 |
242 | return res;
243 | }
244 |
245 | #endif /* __GSINLINE_H__ */
246 |
--------------------------------------------------------------------------------
/ee/gs/include/gsKit.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // gsKit.h - Master header for gsKit. Include _ONLY_THIS_HEADER_
10 | // for gsKit. (Do NOT include gsFont.h, gsCore.h, etc)
11 | //
12 |
13 | #ifndef __GSKIT_H__
14 | #define __GSKIT_H__
15 |
16 | #include
17 | #include
18 | #include
19 |
20 | #include "dmaKit.h"
21 |
22 | #include "gsInit.h"
23 | #include "gsMisc.h"
24 | #include "gsCore.h"
25 | #include "gsPrimitive.h"
26 | #include "gsTexture.h"
27 | #include "gsFontM.h"
28 | #include "gsHires.h"
29 | #include "gsTexManager.h"
30 |
31 | #endif /* __GSKIT_H__ */
32 |
--------------------------------------------------------------------------------
/ee/gs/include/gsMisc.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // gsMisc.h - Header for gsMisc.c
10 | //
11 |
12 | #ifndef __GSMISC_H__
13 | #define __GSMISC_H__
14 |
15 | #include "gsKit.h"
16 |
17 | #ifdef __cplusplus
18 | extern "C" {
19 | #endif
20 |
21 | void gsKit_setup_tbw(GSTEXTURE *Texture);
22 | void gsKit_vram_dump(GSGLOBAL *gsGlobal, char *Path, u32 StartAddr, u32 EndAddr);
23 |
24 | #ifdef __cplusplus
25 | }
26 | #endif
27 |
28 | #endif /* __GSMISC_H__ */
29 |
--------------------------------------------------------------------------------
/ee/gs/include/gsPrimitive.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // gsPrimitive.h - Header for gsPrimitive.c
10 | //
11 | // Parts taken from emoon's BreakPoint Demo Library
12 | //
13 |
14 | #ifndef __GSPRIMITIVE_H__
15 | #define __GSPRIMITIVE_H__
16 |
17 | #include "gsKit.h"
18 |
19 | #define GS_SETREG_PRIM(prim, iip, tme, fge, abe, aa1, fst, ctxt, fix) \
20 | ((u64)(prim) | ((u64)(iip) << 3) | ((u64)(tme) << 4) | \
21 | ((u64)(fge) << 5) | ((u64)(abe) << 6) | ((u64)(aa1) << 7) | \
22 | ((u64)(fst) << 8) | ((u64)(ctxt) << 9) | ((u64)(fix) << 10))
23 |
24 | #define GS_SETREG_PRMODE(iip, tme, fge, abe, aa1, fst, ctxt, fix) \
25 | (((u64)(iip) << 3) | ((u64)(tme) << 4) | \
26 | ((u64)(fge) << 5) | ((u64)(abe) << 6) | ((u64)(aa1) << 7) | \
27 | ((u64)(fst) << 8) | ((u64)(ctxt) << 9) | ((u64)(fix) << 10))
28 |
29 | #define GS_SETREG_PRMODECONT(ac) ((u64)(ac))
30 |
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #endif
34 |
35 | void gsKit_prim_point(GSGLOBAL *gsGlobal, float x, float y, int iz, u64 color);
36 | void gsKit_prim_list_points(GSGLOBAL *gsGlobal, int count, const GSPRIMPOINT *vertices);
37 |
38 | void gsKit_prim_line_3d(GSGLOBAL *gsGlobal, float x1, float y1, int iz1,
39 | float x2, float y2, int iz2, u64 color);
40 |
41 | void gsKit_prim_line_goraud_3d(GSGLOBAL *gsGlobal, float x1, float y1, int iz1, float x2, float y2, int iz2, u64 color1, u64 color2);
42 | void gsKit_prim_list_line_goraud_3d(GSGLOBAL *gsGlobal, int count, const GSPRIMPOINT *vertices);
43 |
44 | void gsKit_prim_line_strip(GSGLOBAL *gsGlobal, float *LineStrip, int segments, int iz, u64 color);
45 |
46 | void gsKit_prim_line_strip_3d(GSGLOBAL *gsGlobal, float *LineStrip, int segments, u64 color);
47 |
48 | void gsKit_prim_sprite(GSGLOBAL *gsGlobal, float x1, float y1, float x2, float y2, int iz, u64 color);
49 | void gsKit_prim_list_sprite_gouraud_3d(GSGLOBAL *gsGlobal, int count, const GSPRIMPOINT *vertices);
50 | void gsKit_prim_list_sprite_flat(GSGLOBAL *gsGlobal, int count, const u128 *flatContent);
51 | void gsKit_prim_list_sprite_flat_color(GSGLOBAL *gsGlobal, gs_rgbaq color, int count, const gs_xyz2 *vertices);
52 |
53 | void gsKit_prim_triangle_3d(GSGLOBAL *gsGlobal, float x1, float y1, int iz1,
54 | float x2, float y2, int iz2,
55 | float x3, float y3, int iz3, u64 color);
56 |
57 | void gsKit_prim_triangle_strip(GSGLOBAL *gsGlobal, float *TriStrip, int segments, int iz, u64 color);
58 |
59 | void gsKit_prim_triangle_strip_3d(GSGLOBAL *gsGlobal, float *TriStrip, int segments, u64 color);
60 |
61 | void gsKit_prim_triangle_fan(GSGLOBAL *gsGlobal, float *TriFan, int verticies, int iz, u64 color);
62 |
63 | void gsKit_prim_triangle_fan_3d(GSGLOBAL *gsGlobal, float *TriFan, int verticies, u64 color);
64 |
65 | void gsKit_prim_triangle_gouraud_3d(GSGLOBAL *gsGlobal, float x1, float y1, int iz1,
66 | float x2, float y2, int iz2,
67 | float x3, float y3, int iz3,
68 | u64 color1, u64 color2, u64 color3);
69 |
70 | void gsKit_prim_list_triangle_gouraud_3d(GSGLOBAL *gsGlobal, int count, const GSPRIMPOINT *vertices);
71 |
72 | void gsKit_prim_quad_3d(GSGLOBAL *gsGlobal, float x1, float y1, int iz1,
73 | float x2, float y2, int iz2,
74 | float x3, float y3, int iz3,
75 | float x4, float y4, int iz4, u64 color);
76 |
77 | void gsKit_prim_quad_gouraud_3d(GSGLOBAL *gsGlobal, float x1, float y1, int iz1,
78 | float x2, float y2, int iz2,
79 | float x3, float y3, int iz3,
80 | float x4, float y4, int iz4,
81 | u64 color1, u64 color2,
82 | u64 color3, u64 color4);
83 |
84 |
85 | #define gsKit_prim_line(gsGlobal, x1, y1, \
86 | x2, y2, \
87 | z, color) \
88 | gsKit_prim_line_3d(gsGlobal, x1, y1, z, \
89 | x2, y2, z, color);
90 |
91 | #define gsKit_prim_line_goraud(gsGlobal, x1, y1, \
92 | x2, y2, \
93 | z, color1, color2) \
94 | gsKit_prim_line_goraud_3d(gsGlobal, x1, y1, z, \
95 | x2, y2, z, color1, color2);
96 |
97 | #define gsKit_prim_triangle(gsGlobal, x1, y1, \
98 | x2, y2, \
99 | x3, y3, \
100 | z, color) \
101 | gsKit_prim_triangle_3d(gsGlobal, x1, y1, z, \
102 | x2, y2, z, \
103 | x3, y3, z, color);
104 |
105 | #define gsKit_prim_triangle_gouraud(gsGlobal, x1, y1, \
106 | x2, y2, \
107 | x3, y3, z, \
108 | color1, color2, color3) \
109 | gsKit_prim_triangle_gouraud_3d(gsGlobal, x1, y1, z, \
110 | x2, y2, z, \
111 | x3, y3, z, \
112 | color1, color2, color3); \
113 |
114 | #define gsKit_prim_quad(gsGlobal, x1, y1, \
115 | x2, y2, \
116 | x3, y3, \
117 | x4, y4, \
118 | z, color) \
119 | gsKit_prim_quad_3d(gsGlobal, x1, y1, z, \
120 | x2, y2, z, \
121 | x3, y3, z, \
122 | x4, y4, z, color);
123 |
124 | #define gsKit_prim_quad_gouraud(gsGlobal, x1, y1, \
125 | x2, y2, \
126 | x3, y3, \
127 | x4, y4, \
128 | z, color1, color2, color3, color4) \
129 | gsKit_prim_quad_gouraud_3d(gsGlobal, x1, y1, z, \
130 | x2, y2, z, \
131 | x3, y3, z, \
132 | x4, y4, z, \
133 | color1, color2, color3, color4);
134 |
135 |
136 | #ifdef __cplusplus
137 | }
138 | #endif
139 |
140 | #endif /* __GSPRIMITIVE_H__ */
141 |
--------------------------------------------------------------------------------
/ee/gs/include/gsTexManager.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2017 - Rick "Maximus32" Gaiser
6 | // Copyright 2004 - Chris "Neovanglist" Gilbert
7 | // Licenced under Academic Free License version 2.0
8 | // Review gsKit README & LICENSE files for further details.
9 | //
10 | // gsHires.h - Header for gsHires.c
11 | //
12 |
13 | #ifndef __GSTEXMANAGER_H__
14 | #define __GSTEXMANAGER_H__
15 |
16 |
17 | #include "gsKit.h"
18 |
19 |
20 | #ifdef __cplusplus
21 | extern "C" {
22 | #endif
23 |
24 |
25 | enum ETransferMode {
26 | ETM_INLINE = 0,
27 | ETM_DIRECT
28 | };
29 |
30 |
31 | /// Initialize the texture manager
32 | void gsKit_TexManager_init(GSGLOBAL * gsGlobal);
33 |
34 | /// Set the texture transfer mode (inline or direct)
35 | void gsKit_TexManager_setmode(GSGLOBAL * gsGlobal, enum ETransferMode mode);
36 |
37 | /// Bind a texture to VRAM, will automatically transfer the texture.
38 | unsigned int gsKit_TexManager_bind(GSGLOBAL * gsGlobal, GSTEXTURE * tex);
39 |
40 | /// Invalidate a texture, will automatically transfer the texture on next bind call.
41 | void gsKit_TexManager_invalidate(GSGLOBAL * gsGlobal, GSTEXTURE * tex);
42 |
43 | /// Free the texture, this is mainly a performance optimization.
44 | /// The texture will be automatically freed if not used.
45 | void gsKit_TexManager_free(GSGLOBAL * gsGlobal, GSTEXTURE * tex);
46 |
47 | /// When starting a next frame (on vsync/swap), call this function.
48 | /// It updates texture usage statistics.
49 | void gsKit_TexManager_nextFrame(GSGLOBAL * gsGlobal);
50 |
51 |
52 | #ifdef __cplusplus
53 | };
54 | #endif
55 |
56 |
57 | #endif /* __GSTEXMANAGER_H__ */
58 |
--------------------------------------------------------------------------------
/ee/gs/include/gsTexture.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // gsTexture.h - Header for gsTexture.c
10 | //
11 |
12 | #ifndef __GSTEXTURE_H__
13 | #define __GSTEXTURE_H__
14 |
15 | #include "gsKit.h"
16 |
17 | #define GS_ST 0x02
18 | #define GS_UV 0x03
19 | #define GS_TEX0_1 0x06
20 | #define GS_TEX0_2 0x07
21 | #define GS_TEX1_1 0x14
22 | #define GS_TEX1_2 0x15
23 | #define GS_TEX2_1 0x16
24 | #define GS_TEX2_2 0x17
25 | #define GS_TEXCLUT 0x1c
26 | #define GS_SCANMSK 0x22
27 | #define GS_MIPTBP1_1 0x34
28 | #define GS_MIPTBP1_2 0x35
29 | #define GS_MIPTBP2_1 0x36
30 | #define GS_MIPTBP2_2 0x37
31 | #define GS_TEXA 0x3b
32 | #define GS_TEXFLUSH 0x3f
33 |
34 | #define GS_CLUT_NONE 0x00
35 | #define GS_CLUT_PALLETE 0x01
36 | #define GS_CLUT_TEXTURE 0x02
37 |
38 | #define GS_CLUT_STOREMODE_NOLOAD 0x00
39 | #define GS_CLUT_STOREMODE_LOAD 0x01
40 | #define GS_CLUT_STOREMODE_LOAD_CBP0 0x02
41 | #define GS_CLUT_STOREMODE_LOAD_CBP1 0x03
42 | #define GS_CLUT_STOREMODE_COMPARE_CBP0 0x04
43 | #define GS_CLUT_STOREMODE_COMPARE_CBP1 0x05
44 |
45 | #define GS_SETREG_COLCLAMP(clamp) ((u64)(clamp))
46 |
47 | #define GS_SETREG_MIPTBP1_1 GS_SETREG_MIPTBP1
48 | #define GS_SETREG_MIPTBP1_2 GS_SETREG_MIPTBP1
49 | #define GS_SETREG_MIPTBP1(tbp1, tbw1, tbp2, tbw2, tbp3, tbw3) \
50 | ((u64)(tbp1) | ((u64)(tbw1) << 14) | \
51 | ((u64)(tbp2) << 20) | ((u64)(tbw2) << 34) | \
52 | ((u64)(tbp3) << 40) | ((u64)(tbw3) << 54))
53 |
54 | #define GS_SETREG_MIPTBP2_1 GS_SETREG_MIPTBP2
55 | #define GS_SETREG_MIPTBP2_2 GS_SETREG_MIPTBP2
56 | #define GS_SETREG_MIPTBP2(tbp4, tbw4, tbp5, tbw5, tbp6, tbw6) \
57 | ((u64)(tbp4) | ((u64)(tbw4) << 14) | \
58 | ((u64)(tbp5) << 20) | ((u64)(tbw5) << 34) | \
59 | ((u64)(tbp6) << 40) | ((u64)(tbw6) << 54))
60 |
61 | #define GS_SETREG_TEX0_1 GS_SETREG_TEX0
62 | #define GS_SETREG_TEX0_2 GS_SETREG_TEX0
63 | #define GS_SETREG_TEX0(tbp, tbw, psm, tw, th, tcc, tfx,cbp, cpsm, csm, csa, cld) \
64 | ((u64)(tbp) | ((u64)(tbw) << 14) | \
65 | ((u64)(psm) << 20) | ((u64)(tw) << 26) | \
66 | ((u64)(th) << 30) | ((u64)(tcc) << 34) | \
67 | ((u64)(tfx) << 35) | ((u64)(cbp) << 37) | \
68 | ((u64)(cpsm) << 51) | ((u64)(csm) << 55) | \
69 | ((u64)(csa) << 56) | ((u64)(cld) << 61))
70 |
71 | #define GS_SETREG_TEX1_1 GS_SETREG_TEX1
72 | #define GS_SETREG_TEX1_2 GS_SETREG_TEX1
73 | #define GS_SETREG_TEX1(lcm, mxl, mmag, mmin, mtba, l, k) \
74 | ((u64)(lcm) | ((u64)(mxl) << 2) | \
75 | ((u64)(mmag) << 5) | ((u64)(mmin) << 6) | \
76 | ((u64)(mtba) << 9) | ((u64)(l) << 19) | \
77 | ((u64)(k) << 32))
78 |
79 | #define GS_SETREG_TEX2_1 GS_SETREG_TEX2
80 | #define GS_SETREG_TEX2_2 GS_SETREG_TEX2
81 | #define GS_SETREG_TEX2(psm, cbp, cpsm, csm, csa, cld) \
82 | (((u64)(psm) << 20) | ((u64)(cbp) << 37) | \
83 | ((u64)(cpsm) << 51) | ((u64)(csm) << 55) | \
84 | ((u64)(csa) << 56) | ((u64)(cld) << 61))
85 |
86 | #define GS_SETREG_TEXA(ta0, aem, ta1) \
87 | ((u64)(ta0) | ((u64)(aem) << 15) | ((u64)(ta1) << 32))
88 |
89 | #define GS_SETREG_TEXCLUT(cbw, cou, cov) \
90 | ((u64)(cbw) | ((u64)(cou) << 6) | ((u64)(cov) << 12))
91 |
92 | #define GS_SETREG_TRXDIR(xdr) ((u64)(xdr))
93 |
94 | #define GS_SETREG_TRXPOS(ssax, ssay, dsax, dsay, dir) \
95 | ((u64)(ssax) | ((u64)(ssay) << 16) | \
96 | ((u64)(dsax) << 32) | ((u64)(dsay) << 48) | \
97 | ((u64)(dir) << 59))
98 |
99 | #define GS_SETREG_TRXREG(rrw, rrh) \
100 | ((u64)(rrw) | ((u64)(rrh) << 32))
101 |
102 | #define GS_SETREG_UV(u, v) ((u64)(u) | ((u64)(v) << 16))
103 |
104 | #define GS_SETREG_STQ(s, t) ((u64)(s) | ((u64)(t) << 32))
105 |
106 | #define GS_SETREG_BITBLTBUF(sbp, sbw, spsm, dbp, dbw, dpsm) \
107 | ((u64)(sbp) | ((u64)(sbw) << 16) | \
108 | ((u64)(spsm) << 24) | ((u64)(dbp) << 32) | \
109 | ((u64)(dbw) << 48) | ((u64)(dpsm) << 56))
110 |
111 | #ifdef __cplusplus
112 | extern "C" {
113 | #endif
114 | u32 gsKit_texture_size_ee(int width, int height, int psm);
115 | u32 gsKit_texture_size(int width, int height, int psm);
116 | void gsKit_texture_to_psm16(GSTEXTURE *Texture);
117 | void gsKit_texture_send(u32 *mem, int width, int height, u32 tbp, u32 psm, u32 tbw, u8 clut);
118 | void gsKit_texture_send_inline(GSGLOBAL *gsGlobal, u32 *mem, int width, int height, u32 tbp, u32 psm, u32 tbw, u8 clut);
119 | void gsKit_texture_upload(GSGLOBAL *gsGlobal, GSTEXTURE *Texture);
120 |
121 | void gsKit_prim_sprite_texture_3d(GSGLOBAL *gsGlobal, const GSTEXTURE *Texture, float x1, float y1, int iz1, float u1, float v1,
122 | float x2, float y2, int iz2, float u2, float v2,
123 | u64 color);
124 |
125 | void gsKit_prim_sprite_striped_texture_3d(GSGLOBAL *gsGlobal, const GSTEXTURE *Texture, float x1, float y1, int iz1, float u1, float v1,
126 | float x2, float y2, int iz2, float u2, float v2,
127 | u64 color);
128 |
129 | void gskit_prim_list_sprite_texture_uv_3d(GSGLOBAL *gsGlobal, const GSTEXTURE *Texture, int count, const GSPRIMUVPOINT *vertices);
130 | void gskit_prim_list_sprite_texture_uv_flat(GSGLOBAL *gsGlobal, const GSTEXTURE *Texture, int count, const u128 *flatContent);
131 | void gskit_prim_list_sprite_texture_uv_flat_color(GSGLOBAL *gsGlobal, const GSTEXTURE *Texture, gs_rgbaq color, int count, const GSPRIMUVPOINTFLAT *vertices);
132 |
133 | void gsKit_prim_triangle_texture_3d(GSGLOBAL *gsGlobal, GSTEXTURE *Texture,
134 | float x1, float y1, int iz1, float u1, float v1,
135 | float x2, float y2, int iz2, float u2, float v2,
136 | float x3, float y3, int iz3, float u3, float v3, u64 color);
137 |
138 | void gsKit_prim_triangle_goraud_texture_3d(GSGLOBAL *gsGlobal, GSTEXTURE *Texture,
139 | float x1, float y1, int iz1, float u1, float v1,
140 | float x2, float y2, int iz2, float u2, float v2,
141 | float x3, float y3, int iz3, float u3, float v3,
142 | u64 color1, u64 color2, u64 color3);
143 |
144 | void gsKit_prim_list_triangle_goraud_texture_uv_3d(GSGLOBAL *gsGlobal, GSTEXTURE *Texture, int count, const GSPRIMUVPOINT *vertices);
145 | void gsKit_prim_list_triangle_goraud_texture_stq_3d(GSGLOBAL *gsGlobal, GSTEXTURE *Texture, int count, const GSPRIMSTQPOINT *vertices);
146 |
147 | void gsKit_prim_triangle_strip_texture(GSGLOBAL *gsGlobal, GSTEXTURE *Texture,
148 | float *TriStrip, int segments, int iz, u64 color);
149 |
150 | void gsKit_prim_triangle_strip_texture_3d(GSGLOBAL *gsGlobal, GSTEXTURE *Texture,
151 | float *TriStrip, int segments, u64 color);
152 |
153 | void gsKit_prim_triangle_fan_texture(GSGLOBAL *gsGlobal, GSTEXTURE *Texture,
154 | float *TriFan, int verticies, int iz, u64 color);
155 |
156 | void gsKit_prim_triangle_fan_texture_3d(GSGLOBAL *gsGlobal, GSTEXTURE *Texture,
157 | float *TriFan, int verticies, u64 color);
158 |
159 | void gsKit_prim_quad_texture_3d(GSGLOBAL *gsGlobal, GSTEXTURE *Texture,
160 | float x1, float y1, int iz1, float u1, float v1,
161 | float x2, float y2, int iz2, float u2, float v2,
162 | float x3, float y3, int iz3, float u3, float v3,
163 | float x4, float y4, int iz4, float u4, float v4, u64 color);
164 |
165 | void gsKit_prim_quad_goraud_texture_3d(GSGLOBAL *gsGlobal, GSTEXTURE *Texture,
166 | float x1, float y1, int iz1, float u1, float v1,
167 | float x2, float y2, int iz2, float u2, float v2,
168 | float x3, float y3, int iz3, float u3, float v3,
169 | float x4, float y4, int iz4, float u4, float v4,
170 | u64 color1, u64 color2, u64 color3, u64 color4);
171 |
172 |
173 | #define gsKit_prim_sprite_texture(gsGlobal, Texture, x1, y1, u1, v1, \
174 | x2, y2, u2, v2, \
175 | z, color) \
176 | gsKit_prim_sprite_texture_3d(gsGlobal, Texture, x1, y1, z, u1, v1, \
177 | x2, y2, z, u2, v2, color);
178 |
179 | #define gsKit_prim_sprite_striped_texture(gsGlobal, Texture, x1, y1, u1, v1, \
180 | x2, y2, u2, v2, \
181 | z, color) \
182 | gsKit_prim_sprite_striped_texture_3d(gsGlobal, Texture, x1, y1, z, u1, v1, \
183 | x2, y2, z, u2, v2, color);
184 |
185 | #define gsKit_prim_triangle_texture(gsGlobal, Texture, x1, y1, u1, v1, \
186 | x2, y2, u2, v2, \
187 | x3, y3, u3, v3, \
188 | z, color) \
189 | gsKit_prim_triangle_texture_3d(gsGlobal, Texture, x1, y1, z, u1, v1, \
190 | x2, y2, z, u2, v2, \
191 | x3, y3, z, u3, v3, color);
192 |
193 | #define gsKit_prim_triangle_goraud_texture(gsGlobal, Texture, x1, y1, u1, v1, \
194 | x2, y2, u2, v2, \
195 | x3, y3, u3, v3, \
196 | z, color1, color2, color3) \
197 | gsKit_prim_triangle_goraud_texture_3d(gsGlobal, Texture, x1, y1, z, u1, v1, \
198 | x2, y2, z, u2, v2, \
199 | x3, y3, z, u3, v3, color1, color2, color3);
200 |
201 | #define gsKit_prim_quad_texture(gsGlobal, Texture, x1, y1, u1, v1, \
202 | x2, y2, u2, v2, \
203 | x3, y3, u3, v3, \
204 | x4, y4, u4, v4, \
205 | z, color) \
206 | gsKit_prim_quad_texture_3d(gsGlobal, Texture, x1, y1, z, u1, v1, \
207 | x2, y2, z, u2, v2, \
208 | x3, y3, z, u3, v3, \
209 | x4, y4, z, u4, v4, color);
210 |
211 | #define gsKit_prim_quad_goraud_texture(gsGlobal, Texture, x1, y1, u1, v1, \
212 | x2, y2, u2, v2, \
213 | x3, y3, u3, v3, \
214 | x4, y4, u4, v4, \
215 | z, color1, color2, color3, color4) \
216 | gsKit_prim_quad_goraud_texture_3d(gsGlobal, Texture, x1, y1, z, u1, v1, \
217 | x2, y2, z, u2, v2, \
218 | x3, y3, z, u3, v3, \
219 | x4, y4, z, u4, v4, color1, color2, color3, color4);
220 |
221 | #ifdef __cplusplus
222 | }
223 | #endif
224 |
225 | #endif /* __GSTEXTURE_H__ */
226 |
--------------------------------------------------------------------------------
/ee/gs/include/gsVU1.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // gsVU1.h - Header for gsVU1.c
10 | //
11 |
12 | #ifndef __GSVU1_H__
13 | #define __GSVU1_H__
14 |
15 | #include "gsKit.h"
16 |
17 | // Nothing here yet!
18 |
19 | #endif /* __GSVU1_H__ */
20 |
--------------------------------------------------------------------------------
/ee/gs/src/gsMisc.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // gsMisc.c - Miscellaneous Helper Routines
10 | //
11 |
12 | #include "gsKit.h"
13 |
14 | #if F_gsKit_setup_tbw
15 | void gsKit_setup_tbw(GSTEXTURE *Texture)
16 | {
17 | if(Texture->PSM == GS_PSM_T8 || Texture->PSM == GS_PSM_T4)
18 | {
19 | Texture->TBW = (-GS_VRAM_TBWALIGN_CLUT)&(Texture->Width+GS_VRAM_TBWALIGN_CLUT-1);
20 | if(Texture->TBW / 64 > 0)
21 | Texture->TBW = (Texture->TBW / 64);
22 | else
23 | Texture->TBW = 1;
24 | }
25 | else
26 | {
27 | Texture->TBW = (-GS_VRAM_TBWALIGN)&(Texture->Width+GS_VRAM_TBWALIGN-1);
28 | if(Texture->TBW / 64 > 0)
29 | Texture->TBW = (Texture->TBW / 64);
30 | else
31 | Texture->TBW = 1;
32 | }
33 | }
34 | #endif
35 |
36 | #if F_gsKit_vram_dump
37 | void gsKit_vram_dump(GSGLOBAL *gsGlobal, char *Path, u32 StartAddr, u32 EndAddr)
38 | {
39 | #if 0
40 | u64* p_store;
41 | u64* p_data;
42 | u32* p_mem;
43 | int packets;
44 | int remain;
45 | int qwc;
46 | int Size;
47 |
48 | printf("THIS IS NOT DONE YET!\n");
49 |
50 | return 0;
51 |
52 | StartAddr = (-GS_VRAM_BLOCKSIZE)&(StartAddr+GS_VRAM_BLOCKSIZE-1);
53 | EndAddr = (-GS_VRAM_BLOCKSIZE)&(EndAddr+GS_VRAM_BLOCKSIZE-1);
54 |
55 | Size = EndAddr - StartAddr;
56 |
57 | qwc = Size / 16;
58 | if( Size % 16 )
59 | {
60 | #ifdef DEBUG
61 | printf("Uneven division of quad word count from VRAM alloc. Rounding up QWC.\n");
62 | #endif
63 | qwc++;
64 | }
65 |
66 | packets = qwc / DMA_MAX_SIZE;
67 | remain = qwc % DMA_MAX_SIZE;
68 |
69 | p_store = p_data = dmaKit_spr_alloc( 7 * 16 );
70 |
71 | FlushCache(0);
72 |
73 | // DMA DATA
74 | *p_data++ = DMA_TAG( 6, 0, DMA_CNT, 0, 0, 0 );
75 | *p_data++ = 0;
76 |
77 | *p_data++ = GIF_TAG( 5, 1, 0, 0, GSKIT_GIF_FLG_PACKED, 1 );
78 | *p_data++ = GIF_AD;
79 |
80 | *p_data++ = GS_SETREG_BITBLTBUF(StartAddr / 64, (4095.9375 / 64), 0, 0, 0, 0);
81 | *p_data++ = GS_BITBLTBUF;
82 |
83 | *p_data++ = GS_SETREG_TRXPOS(0, 0, 0, 0, 0);
84 | *p_data++ = GS_TRXPOS;
85 |
86 | *p_data++ = GS_SETREG_TRXREG(4095.9375, 4095.9375);
87 | *p_data++ = GS_TRXREG;
88 |
89 | *p_data++ = 0;
90 | *p_data++ = GS_FINISH;
91 |
92 | *p_data++ = GS_SETREG_TRXDIR(1);
93 | *p_data++ = GS_TRXDIR;
94 |
95 | dmaKit_send_spr( DMA_CHANNEL_GIF, 0, p_store, 7 );
96 |
97 | while(GS_CSR_FINISH != 1);
98 |
99 | GS_SETREG_CSR_FINISH(1);
100 |
101 | FlushCache(0);
102 |
103 | GS_SETREG_BUSDIR(1);
104 | #endif
105 | }
106 | #endif
107 |
--------------------------------------------------------------------------------
/ee/gs/src/gsVU1.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // gsVU1.c - VU1 Related Routines
10 | //
11 | // Parts taken from emoon's BreakPoint Demo Library
12 | //
13 |
14 | #include "gsKit.h"
15 |
16 | // Nothing here yet!
17 |
--------------------------------------------------------------------------------
/ee/toolkit/include/gsToolkit.h:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // gsToolkit.h - Header for gsToolkit.c
10 | //
11 |
12 | #ifndef __GSTOOLKIT_H__
13 | #define __GSTOOLKIT_H__
14 |
15 | #include "gsKit.h"
16 |
17 | struct gsBitMapFileHeader
18 | {
19 | u16 Type;
20 | u32 Size;
21 | u16 Reserved1;
22 | u16 Reserved2;
23 | u32 Offset;
24 | } __attribute__ ((packed));
25 | typedef struct gsBitMapFileHeader GSBMFHDR;
26 |
27 | struct gsBitMapInfoHeader
28 | {
29 | u32 Size;
30 | u32 Width;
31 | u32 Height;
32 | u16 Planes;
33 | u16 BitCount;
34 | u32 Compression;
35 | u32 SizeImage;
36 | u32 XPelsPerMeter;
37 | u32 YPelsPerMeter;
38 | u32 ColorUsed;
39 | u32 ColorImportant;
40 | } __attribute__ ((packed));
41 | typedef struct gsBitMapInfoHeader GSBMIHDR;
42 |
43 | struct gsBitMapClut
44 | {
45 | u8 Blue;
46 | u8 Green;
47 | u8 Red;
48 | u8 Alpha;
49 | } __attribute__ ((packed));
50 | typedef struct gsBitMapClut GSBMCLUT;
51 |
52 | struct gsBitmap
53 | {
54 | GSBMFHDR FileHeader;
55 | GSBMIHDR InfoHeader;
56 | char *Texture;
57 | GSBMCLUT *Clut;
58 | };
59 | typedef struct gsBitmap GSBITMAP;
60 |
61 | //remove fontm specific things here
62 | #define GSKIT_FTYPE_FNT 0x00
63 | #define GSKIT_FTYPE_BMP_DAT 0x01
64 | #define GSKIT_FTYPE_PNG_DAT 0x02
65 |
66 | /// gsKit Font Structure
67 | /// This structure holds all relevant data for any
68 | /// given font object, regardless of original format or type.
69 | struct gsFont
70 | {
71 | char *Path; ///< Path (string) to the Font File
72 | char *Path_DAT; ///< Path (string) to the Glyph DAT File
73 | u8 Type; ///< Font Type
74 | u8 *RawData; ///< Raw File Data
75 | int RawSize; ///< Raw File Datasize
76 | GSTEXTURE *Texture; ///< Font Texture Object
77 | u32 CharWidth; ///< Character Width
78 | u32 CharHeight; ///< Character Height
79 | u32 HChars; ///< Character Rows
80 | u32 VChars; ///< Character Columns
81 | s16 *Additional; ///< Additional Font Data
82 | int pgcount; /// Number of pages used in one call to gsKit_font_print_scaled
83 | };
84 | typedef struct gsFont GSFONT;
85 |
86 | #ifdef __cplusplus
87 | extern "C" {
88 | #endif
89 |
90 | int gsKit_texture_bmp(GSGLOBAL *gsGlobal, GSTEXTURE *Texture, char *Path);
91 | int gsKit_texture_png(GSGLOBAL *gsGlobal, GSTEXTURE *Texture, char *Path);
92 | int gsKit_texture_jpeg_scale(GSGLOBAL *gsGlobal, GSTEXTURE *Texture, char *Path, bool scale_down);
93 | int gsKit_texture_jpeg(GSGLOBAL *gsGlobal, GSTEXTURE *Texture, char *Path);
94 | int gsKit_texture_tiff(GSGLOBAL *gsGlobal, GSTEXTURE *Texture, char *Path);
95 | int gsKit_texture_tga(GSGLOBAL *gsGlobal, GSTEXTURE *Texture, char *Path);
96 | int gsKit_texture_raw(GSGLOBAL *gsGlobal, GSTEXTURE *Texture, char *Path);
97 |
98 | /// Initialize Font Object (From Memory)
99 | GSFONT *gsKit_init_font(u8 type, char *path);
100 | GSFONT *gsKit_init_font_raw(u8 type, u8 *data, int size);
101 |
102 | int gsKit_font_upload(GSGLOBAL *gsGlobal, GSFONT *gsFont);
103 | int gsKit_font_upload_raw(GSGLOBAL *gsGlobal, GSFONT *gsFont);
104 |
105 | //int gsKit_texture_fnt(GSGLOBAL *gsGlobal, GSFONT *gsFont);
106 | int gsKit_texture_fnt_raw(GSGLOBAL *gsGlobal, GSFONT *gsFont);
107 |
108 | void gsKit_font_print_scaled(GSGLOBAL *gsGlobal, GSFONT *gsFont, float X, float Y, int Z,
109 | float scale, unsigned long color, const char *String);
110 |
111 | #define gsKit_font_print(gsGlobal, gsFont, X, Y, Z, color, String) \
112 | gsKit_font_print_scaled(gsGlobal, gsFont, X, Y, Z, 1.0f, color, String);
113 |
114 | #ifdef __cplusplus
115 | }
116 | #endif
117 |
118 | #endif /* __GSTOOLKIT_H__ */
119 |
--------------------------------------------------------------------------------
/examples/alpha/alpha.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // alpha.c - Example demonstrating gsKit alpha blending operation.
10 | //
11 |
12 | #include
13 | #include
14 |
15 | #include
16 | #include
17 | #include
18 |
19 | int main(int argc, char *argv[])
20 | {
21 | GSGLOBAL *gsGlobal;
22 | // GS_MODE_VGA_640_60
23 | #ifdef HAVE_LIBTIFF
24 | GSTEXTURE Sprite;
25 | u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
26 | #endif
27 | u64 White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
28 | u64 Red = GS_SETREG_RGBAQ(0xFF,0x00,0x00,0x00,0x00);
29 | u64 Green = GS_SETREG_RGBAQ(0x00,0xFF,0x00,0x00,0x00);
30 | u64 Blue = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x00,0x00);
31 | u64 BlueTrans = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x40,0x00);
32 |
33 | float x = 10;
34 | float y = 10;
35 | float width = 150;
36 | float height = 150;
37 |
38 | float VHeight;
39 |
40 | gsGlobal = gsKit_init_global();
41 |
42 | VHeight = gsGlobal->Height;
43 |
44 | gsGlobal->PSM = GS_PSM_CT24;
45 | gsGlobal->PSMZ = GS_PSMZ_16S;
46 | // gsGlobal->DoubleBuffering = GS_SETTING_OFF;
47 | // gsGlobal->ZBuffering = GS_SETTING_OFF;
48 |
49 | dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
50 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
51 |
52 | // Initialize the DMAC
53 | dmaKit_chan_init(DMA_CHANNEL_GIF);
54 |
55 | gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
56 |
57 | gsKit_init_screen(gsGlobal);
58 | #ifdef HAVE_LIBTIFF
59 | Sprite.Delayed = 1;
60 | if(gsKit_texture_tiff(gsGlobal, &Sprite, "host:alpha.tiff") < 0)
61 | {
62 | printf("Loading Failed!\n");
63 | }
64 | #endif
65 | gsKit_mode_switch(gsGlobal, GS_PERSISTENT);
66 |
67 | while(1)
68 | {
69 | if( y <= 10 && (x + width) < (gsGlobal->Width - 10))
70 | x+=10;
71 | else if( (y + height) < (VHeight - 10) && (x + width) >= (gsGlobal->Width - 10) )
72 | y+=10;
73 | else if( (y + height) >= (VHeight - 10) && x > 10 )
74 | x-=10;
75 | else if( y > 10 && x <= 10 )
76 | y-=10;
77 |
78 | gsKit_clear(gsGlobal, White);
79 |
80 | gsKit_prim_quad_gouraud(gsGlobal, 250.0f, 50.0f, 250.0f, 400.0f,
81 | 400.0f, 50.0f, 400.0f, 400.0f,
82 | 1, Red, Green, Blue, White);
83 |
84 | gsKit_prim_sprite(gsGlobal, x, y, x + width, y + height, 2, BlueTrans);
85 |
86 | gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0,1,0,1,0), 0);
87 | gsKit_set_test(gsGlobal, GS_ATEST_OFF);
88 | #ifdef HAVE_LIBTIFF
89 | gsKit_TexManager_bind(gsGlobal, &Sprite);
90 | gsKit_prim_sprite_texture(gsGlobal, &Sprite,
91 | 100.0f, // X1
92 | +400.0f, // Y2
93 | 0.0f, // U1
94 | 0.0f, // V1
95 | Sprite.Width + 310.0f, // X2
96 | Sprite.Height - 250.0f, // Y2
97 | Sprite.Width, // U2
98 | Sprite.Height, // V2
99 | 3,
100 | TexCol);
101 | #endif
102 | gsKit_set_test(gsGlobal, GS_ATEST_ON);
103 | gsKit_set_primalpha(gsGlobal, GS_BLEND_BACK2FRONT, 0);
104 |
105 | gsKit_sync_flip(gsGlobal);
106 |
107 | gsKit_queue_exec(gsGlobal);
108 |
109 | gsKit_queue_reset(gsGlobal->Per_Queue);
110 |
111 | gsKit_TexManager_nextFrame(gsGlobal);
112 | }
113 |
114 | return 0;
115 | }
116 |
--------------------------------------------------------------------------------
/examples/alpha/alpha.tiff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/alpha/alpha.tiff
--------------------------------------------------------------------------------
/examples/atlas/atlas.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // textures.c - Example demonstrating gsKit texture operation.
10 | //
11 |
12 | #include
13 | #include
14 |
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 |
21 | struct runnerUV {
22 | uint32_t u0, v0;
23 | uint32_t u1, v1;
24 | };
25 |
26 | typedef struct runnerUV RunnerUV;
27 |
28 | #define RUNNER_PER_LINE_SCREEN 16
29 | #define RUNNER_PER_COLMN_SCREEN 11
30 | #define TOTAL_RUNNERS_SCREEN (RUNNER_PER_LINE_SCREEN * RUNNER_PER_COLMN_SCREEN)
31 |
32 | #define RUNNER_PER_LINE 8
33 | #define RUNNER_PER_COLUMN 8
34 | #define TOTAL_RUNNERS (RUNNER_PER_LINE * RUNNER_PER_COLUMN)
35 |
36 | #define RUNNER_WIDTH 40
37 | #define RUNNER_HEIGHT 40
38 |
39 | static void getRunnerUV(uint32_t index, RunnerUV *runUV) {
40 | uint32_t line = index / RUNNER_PER_LINE;
41 | uint32_t col = index % RUNNER_PER_LINE;
42 |
43 | runUV->u0 = col * RUNNER_WIDTH;
44 | runUV->v0 = line * RUNNER_HEIGHT;
45 | runUV->u1 = runUV->u0 + RUNNER_WIDTH;
46 | runUV->v1 = runUV->v0 + RUNNER_HEIGHT;
47 | }
48 |
49 | int main(int argc, char *argv[])
50 | {
51 | GSGLOBAL *gsGlobal;
52 | GSTEXTURE atlas;
53 | RunnerUV runUV;
54 | uint32_t index = 0;
55 | uint32_t totalVertices = 2 * TOTAL_RUNNERS_SCREEN;
56 | uint64_t White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
57 | gs_rgbaq color = color_to_RGBAQ(0x80, 0x80, 0x80, 0x80, 0);
58 |
59 | gsGlobal = gsKit_init_global();
60 |
61 | gsGlobal->PSM = GS_PSM_CT24;
62 | gsGlobal->PSMZ = GS_PSMZ_16S;
63 |
64 | dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
65 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
66 |
67 | // Initialize the DMAC
68 | dmaKit_chan_init(DMA_CHANNEL_GIF);
69 |
70 | gsKit_init_screen(gsGlobal);
71 | gsKit_TexManager_init(gsGlobal);
72 | gsKit_mode_switch(gsGlobal, GS_ONESHOT);
73 |
74 | atlas.Delayed = 1;
75 | gsKit_texture_png(gsGlobal, &atlas, "runner_atlas.png");
76 | gsKit_TexManager_bind(gsGlobal, &atlas);
77 | printf("Atlas Height: %i\n",atlas.Height);
78 | printf("Atlas Width: %i\n",atlas.Width);
79 |
80 | printf("Atlas VRAM Range = 0x%X - 0x%X\n",atlas.Vram, atlas.Vram +gsKit_texture_size(atlas.Width, atlas.Height, atlas.PSM) - 1);
81 |
82 | gsKit_set_clamp(gsGlobal, GS_CMODE_CLAMP);
83 |
84 | GSPRIMUVPOINTFLAT *verts = (GSPRIMUVPOINTFLAT*)malloc(sizeof(GSPRIMUVPOINTFLAT) * totalVertices);
85 | for (int i = 0; i < TOTAL_RUNNERS_SCREEN; i++) {
86 | int line = i / RUNNER_PER_LINE_SCREEN;
87 | int col = i % RUNNER_PER_LINE_SCREEN;
88 |
89 | int x0 = col * RUNNER_WIDTH;
90 | int y0 = line * RUNNER_HEIGHT;
91 | int x1 = x0 + RUNNER_WIDTH;
92 | int y1 = y0 + RUNNER_HEIGHT;
93 |
94 | verts[i*2].xyz2 = vertex_to_XYZ2(gsGlobal, x0, y0, 0);
95 | verts[i*2+1].xyz2 = vertex_to_XYZ2(gsGlobal, x1, y1, 0);
96 | }
97 |
98 | while(1)
99 | {
100 | for (uint32_t i = 0; i < TOTAL_RUNNERS_SCREEN; i++) {
101 | uint32_t finalRunnerIndex = (index + i) % TOTAL_RUNNERS;
102 | getRunnerUV(finalRunnerIndex, &runUV);
103 | verts[i*2].uv = vertex_to_UV(&atlas, runUV.u0, runUV.v0);
104 | verts[i*2+1].uv = vertex_to_UV(&atlas, runUV.u1, runUV.v1);
105 | }
106 |
107 | gsKit_clear(gsGlobal, White);
108 | gskit_prim_list_sprite_texture_uv_flat_color(gsGlobal, &atlas, color, totalVertices, verts);
109 |
110 | gsKit_queue_exec(gsGlobal);
111 | gsKit_sync_flip(gsGlobal);
112 | gsKit_TexManager_nextFrame(gsGlobal);
113 |
114 | index = (index + 1) % TOTAL_RUNNERS;
115 | }
116 |
117 | free(verts);
118 |
119 | return 0;
120 | }
121 |
--------------------------------------------------------------------------------
/examples/atlas/runner_atlas.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/atlas/runner_atlas.png
--------------------------------------------------------------------------------
/examples/basic/basic.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // basic.c - Example demonstrating basic gsKit operation.
10 | //
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | int main(int argc, char *argv[])
17 | {
18 | u64 White, Black, Red, Green, Blue, BlueTrans, RedTrans, GreenTrans, WhiteTrans;
19 | GSGLOBAL *gsGlobal;
20 |
21 | float x = 10;
22 | float y = 10;
23 | float width = 150;
24 | float height = 150;
25 |
26 | float VHeight;
27 |
28 | float *LineStrip;
29 | float *LineStripPtr;
30 | float *TriStrip;
31 | float *TriStripPtr;
32 | float *TriFanPtr;
33 | float *TriFan;
34 |
35 | gsGlobal = gsKit_init_global();
36 |
37 | // By default the gsKit_init_global() uses an autodetected interlaced field mode
38 | // To set a new mode set these five variables for the resolution desired and
39 | // mode desired
40 |
41 | // Some examples
42 | // Make sure that gsGlobal->Height is a factor of the mode's gsGlobal->DH
43 |
44 | // gsGlobal->Mode = GS_MODE_NTSC
45 | // gsGlobal->Interlace = GS_INTERLACED;
46 | // gsGlobal->Field = GS_FIELD;
47 | // gsGlobal->Width = 640;
48 | // gsGlobal->Height = 448;
49 |
50 | // gsGlobal->Mode = GS_MODE_PAL;
51 | // gsGlobal->Interlace = GS_INTERLACED;
52 | // gsGlobal->Field = GS_FIELD;
53 | // gsGlobal->Width = 640;
54 | // gsGlobal->Height = 512;
55 |
56 | // gsGlobal->Mode = GS_MODE_DTV_480P;
57 | // gsGlobal->Interlace = GS_NONINTERLACED;
58 | // gsGlobal->Field = GS_FRAME;
59 | // gsGlobal->Width = 720;
60 | // gsGlobal->Height = 480;
61 |
62 | // gsGlobal->Mode = GS_MODE_DTV_1080I;
63 | // gsGlobal->Interlace = GS_INTERLACED;
64 | // gsGlobal->Field = GS_FIELD;
65 | // gsGlobal->Width = 640;
66 | // gsGlobal->Height = 540;
67 | // gsGlobal->PSM = GS_PSM_CT16;
68 | // gsGlobal->PSMZ = GS_PSMZ_16;
69 | // gsGlobal->Dithering = GS_SETTING_ON;
70 |
71 | // A width of 640 would work as well
72 | // However a height of 720 doesn't seem to work well
73 | // gsGlobal->Mode = GS_MODE_DTV_720P;
74 | // gsGlobal->Interlace = GS_NONINTERLACED;
75 | // gsGlobal->Field = GS_FRAME;
76 | // gsGlobal->Width = 640;
77 | // gsGlobal->Height = 360;
78 | // gsGlobal->PSM = GS_PSM_CT16;
79 | // gsGlobal->PSMZ = GS_PSMZ_16;
80 |
81 | // You can use these to turn off Z/Double Buffering. They are on by default.
82 | // gsGlobal->DoubleBuffering = GS_SETTING_OFF;
83 | // gsGlobal->ZBuffering = GS_SETTING_OFF;
84 |
85 | // This makes things look marginally better in half-buffer mode...
86 | // however on some CRT and all LCD, it makes a really horrible screen shake.
87 | // Uncomment this to disable it. (It is on by default)
88 | // gsGlobal->DoSubOffset = GS_SETTING_OFF;
89 |
90 | gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
91 |
92 | VHeight = gsGlobal->Height;
93 |
94 | LineStripPtr = LineStrip = malloc(12 * sizeof(float));
95 | *LineStrip++ = 75; // Segment 1 X
96 | *LineStrip++ = 250; // Segment 1 Y
97 | *LineStrip++ = 125; // Segment 2 X
98 | *LineStrip++ = 290; // Segment 2 Y
99 | *LineStrip++ = 100; // Segment 3 X
100 | *LineStrip++ = 350; // Segment 3 Y
101 | *LineStrip++ = 50; // Segment 4 X
102 | *LineStrip++ = 350; // Segment 4 Y
103 | *LineStrip++ = 25; // Segment 6 X
104 | *LineStrip++ = 290; // Segment 6 X
105 | *LineStrip++ = 75; // Segment 6 Y
106 | *LineStrip++ = 250; // Segment 6 Y
107 |
108 | TriStripPtr = TriStrip = malloc(12 * sizeof(float));
109 | *TriStrip++ = 550;
110 | *TriStrip++ = 100;
111 | *TriStrip++ = 525;
112 | *TriStrip++ = 125;
113 | *TriStrip++ = 575;
114 | *TriStrip++ = 125;
115 | *TriStrip++ = 550;
116 | *TriStrip++ = 150;
117 | *TriStrip++ = 600;
118 | *TriStrip++ = 150;
119 | *TriStrip++ = 575;
120 | *TriStrip++ = 175;
121 |
122 | TriFanPtr = TriFan = malloc(16 * sizeof(float));
123 | *TriFan++ = 300;
124 | *TriFan++ = 100;
125 | *TriFan++ = 225;
126 | *TriFan++ = 100;
127 | *TriFan++ = 235;
128 | *TriFan++ = 75;
129 | *TriFan++ = 265;
130 | *TriFan++ = 40;
131 | *TriFan++ = 300;
132 | *TriFan++ = 25;
133 | *TriFan++ = 335;
134 | *TriFan++ = 40;
135 | *TriFan++ = 365;
136 | *TriFan++ = 75;
137 | *TriFan++ = 375;
138 | *TriFan++ = 100;
139 |
140 | dmaKit_init(D_CTRL_RELE_OFF, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
141 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
142 |
143 | // Initialize the DMAC
144 | dmaKit_chan_init(DMA_CHANNEL_GIF);
145 |
146 | White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
147 | Black = GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00);
148 | Red = GS_SETREG_RGBAQ(0xFF,0x00,0x00,0x00,0x00);
149 | Green = GS_SETREG_RGBAQ(0x00,0xFF,0x00,0x00,0x00);
150 | Blue = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x00,0x00);
151 |
152 | BlueTrans = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x40,0x00);
153 | RedTrans = GS_SETREG_RGBAQ(0xFF,0x00,0x00,0x60,0x00);
154 | GreenTrans = GS_SETREG_RGBAQ(0x00,0xFF,0x00,0x50,0x00);
155 | WhiteTrans = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x50,0x00);
156 |
157 | gsKit_init_screen(gsGlobal);
158 |
159 | gsKit_mode_switch(gsGlobal, GS_PERSISTENT);
160 |
161 | gsKit_clear(gsGlobal, White);
162 |
163 | gsKit_set_test(gsGlobal, GS_ZTEST_OFF);
164 |
165 | gsKit_prim_line_strip(gsGlobal, LineStripPtr, 6, 1, Black);
166 |
167 | gsKit_prim_triangle_strip(gsGlobal, TriStripPtr, 6, 1, Red);
168 |
169 | gsKit_prim_line(gsGlobal, 525.0f, 125.0f, 575.0f, 125.0f, 1, Black);
170 | gsKit_prim_line(gsGlobal, 550.0f, 150.0f, 600.0f, 100.0f, 1, Black);
171 |
172 | gsKit_prim_point(gsGlobal, 575.0f, 75.0f, 1, Black);
173 | gsKit_prim_point(gsGlobal, 600.0f, 100.0f, 1, Black);
174 | gsKit_prim_point(gsGlobal, 625.0f, 125.0f, 1, Black);
175 |
176 | gsKit_prim_quad(gsGlobal, 150.0f, 150.0f,
177 | 150.0f, 400.0f,
178 | 450.0f, 150.0f,
179 | 450.0f, 400.0f, 2, Green);
180 |
181 | gsKit_set_test(gsGlobal, GS_ZTEST_ON);
182 |
183 | gsKit_prim_triangle_fan(gsGlobal, TriFanPtr, 8, 5, Black);
184 |
185 | gsKit_prim_quad_gouraud(gsGlobal, 500.0f, 250.0f,
186 | 500.0f, 350.0f,
187 | 600.0f, 250.0f,
188 | 600.0f, 350.0f, 2,
189 | Red, Green, Blue, Black);
190 |
191 | gsKit_prim_triangle_gouraud(gsGlobal, 280.0f, 200.0f,
192 | 280.0f, 350.0f,
193 | 180.0f, 350.0f, 5,
194 | Blue, Red, White);
195 |
196 | // Temporarily apply a scissor box that covers only part of the red triangle
197 | gsKit_set_scissor(gsGlobal, GS_SETREG_SCISSOR(300.0f, 350.0f, 200.0f, 400.0f));
198 | gsKit_prim_triangle(gsGlobal, 300.0f, 200.0f, 300.0f, 350.0f, 400.0f, 350.0f, 3, Red);
199 | gsKit_set_scissor(gsGlobal, GS_SCISSOR_RESET);
200 |
201 | gsKit_prim_sprite(gsGlobal, 400.0f, 100.0f, 500.0f, 200.0f, 5, Red);
202 |
203 | gsKit_mode_switch(gsGlobal, GS_ONESHOT);
204 |
205 | while(1)
206 | {
207 | if( y <= 10 && (x + width) < (gsGlobal->Width - 10))
208 | x+=10;
209 | else if( (y + height) < (VHeight - 10) && (x + width) >= (gsGlobal->Width - 10) )
210 | y+=10;
211 | else if( (y + height) >= (VHeight - 10) && x > 10 )
212 | x-=10;
213 | else if( y > 10 && x <= 10 )
214 | y-=10;
215 |
216 | gsKit_prim_sprite(gsGlobal, x, y, x + width, y + height, 4, BlueTrans);
217 |
218 | // RedTrans must be a oneshot for proper blending!
219 | gsKit_prim_sprite(gsGlobal, 100.0f, 100.0f, 200.0f, 200.0f, 5, RedTrans);
220 | gsKit_prim_sprite(gsGlobal, 100.0f, 200.0f, 250.0f, 250.0f, 5, GreenTrans);
221 | gsKit_prim_sprite(gsGlobal, 200.0f, 250.0f, 275.0f, 275.0f, 5, WhiteTrans);
222 |
223 | gsKit_queue_exec(gsGlobal);
224 |
225 | // Flip before exec to take advantage of DMA execution double buffering.
226 | gsKit_sync_flip(gsGlobal);
227 |
228 | }
229 |
230 | return 0;
231 | }
232 |
--------------------------------------------------------------------------------
/examples/bigtex/bigtex.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/bigtex/bigtex.bmp
--------------------------------------------------------------------------------
/examples/bigtex/bigtex.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // bigtex.c - Example demonstrating gsKit texture operation.
10 | //
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | #include
17 |
18 | int main(int argc, char *argv[])
19 | {
20 | GSGLOBAL *gsGlobal;
21 | GSTEXTURE bigtex;
22 | u64 Black = GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00);
23 | u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
24 |
25 | float x;
26 | float x2;
27 | int shrinkx;
28 | int shrinkx2;
29 |
30 |
31 | gsGlobal = gsKit_init_global()
32 |
33 | // gsGlobal->DoubleBuffering = GS_SETTING_OFF;
34 | gsGlobal->ZBuffering = GS_SETTING_OFF;
35 |
36 | dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
37 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
38 |
39 | // Initialize the DMAC
40 | dmaKit_chan_init(DMA_CHANNEL_GIF);
41 |
42 | gsKit_init_screen(gsGlobal);
43 |
44 | bigtex.Width = 640;
45 | bigtex.Height = 480;
46 | bigtex.PSM = GS_PSM_CT24;
47 | bigtex.Filter = GS_FILTER_NEAREST;
48 | bigtex.Delayed = 1;
49 |
50 | // gsKit_texture_raw(gsGlobal, &bigtex, "host:bigtex.raw");
51 | gsKit_texture_bmp(gsGlobal, &bigtex, "host:bigtex.bmp");
52 | // gsKit_texture_jpeg(gsGlobal, &bigtex, "host:bigtex.jpg");
53 |
54 |
55 | x = 0.0f;
56 | x2 = gsGlobal->Width;
57 | shrinkx = 1;
58 | shrinkx2 = 0;
59 |
60 | gsKit_mode_switch(gsGlobal, GS_ONESHOT);
61 |
62 | while(1)
63 | {
64 | gsKit_clear(gsGlobal, Black);
65 |
66 | gsKit_set_clamp(gsGlobal, GS_CMODE_CLAMP);
67 |
68 | gsKit_TexManager_bind(gsGlobal, &bigtex);
69 | gsKit_prim_sprite_striped_texture(gsGlobal, &bigtex, x, // X1
70 | // gsKit_prim_sprite_texture(gsGlobal, &bigtex, x, // X1
71 | 0.0f, // Y2
72 | 0.0f, // U1
73 | 0.0f, // V1
74 | x2, // X2
75 | bigtex.Height, // Y2
76 | bigtex.Width, // U2
77 | bigtex.Height, // V2
78 | 2,
79 | TexCol);
80 |
81 | gsKit_queue_exec(gsGlobal);
82 |
83 | gsKit_sync_flip(gsGlobal);
84 |
85 | gsKit_TexManager_nextFrame(gsGlobal);
86 |
87 | if(shrinkx)
88 | {
89 | if(x < 78.0f)
90 | x += 0.25f;
91 | else
92 | shrinkx = 0;
93 | }
94 | else
95 | {
96 | if(x > 0.0f)
97 | x -= 0.25f;
98 | else
99 | shrinkx = 1;
100 | }
101 |
102 | if(shrinkx2)
103 | {
104 | if(x2 < gsGlobal->Width)
105 | x2 += 0.25f;
106 | else
107 | shrinkx2 = 0;
108 | }
109 | else
110 | {
111 | if(x2 > (gsGlobal->Width - 78.0f))
112 | x2 -= 0.25f;
113 | else
114 | shrinkx2 = 1;
115 | }
116 |
117 | }
118 |
119 | return 0;
120 | }
121 |
--------------------------------------------------------------------------------
/examples/bigtex/bigtex.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/bigtex/bigtex.jpg
--------------------------------------------------------------------------------
/examples/bigtex/bigtex.raw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/bigtex/bigtex.raw
--------------------------------------------------------------------------------
/examples/clut/clut.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // textures.c - Example demonstrating gsKit texture operation.
10 | //
11 |
12 | #include
13 | #include
14 |
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 |
21 | #define CLUT_SIZE 256
22 | #define TEXTURE_WIDTH 320
23 | #define TEXTURE_HEIGHT 240
24 |
25 | int main(int argc, char *argv[])
26 | {
27 | GSGLOBAL *gsGlobal;
28 | GSTEXTURE tex;
29 | uint32_t i, j, offset;
30 | uint32_t totalVertices = 2;
31 | uint64_t White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
32 | gs_rgbaq color = color_to_RGBAQ(0x80, 0x80, 0x80, 0x80, 0);
33 |
34 | gsGlobal = gsKit_init_global();
35 |
36 | gsGlobal->PSM = GS_PSM_CT24;
37 | gsGlobal->PSMZ = GS_PSMZ_16S;
38 |
39 | dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
40 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
41 |
42 | // Initialize the DMAC
43 | dmaKit_chan_init(DMA_CHANNEL_GIF);
44 |
45 | gsKit_init_screen(gsGlobal);
46 | gsKit_TexManager_init(gsGlobal);
47 | gsKit_mode_switch(gsGlobal, GS_ONESHOT);
48 |
49 | tex.Width = TEXTURE_WIDTH;
50 | tex.Height = TEXTURE_HEIGHT;
51 | tex.PSM = GS_PSM_T8;
52 | tex.ClutPSM = GS_PSM_CT32;
53 | tex.Clut = memalign(128, gsKit_texture_size_ee(CLUT_SIZE, 1, tex.ClutPSM));
54 | tex.Mem = memalign(128, gsKit_texture_size_ee(tex.Width, tex.Height, tex.PSM));
55 |
56 | printf("Tex VRAM Range = 0x%X - 0x%X\n",tex.Vram, tex.Vram +gsKit_texture_size(tex.Width, tex.Height, tex.PSM) - 1);
57 |
58 | gsKit_set_clamp(gsGlobal, GS_CMODE_CLAMP);
59 |
60 | // initialize texture
61 | uint8_t *tex256 = (uint8_t*)tex.Mem;
62 | for (j = 0; j < tex.Height; ++j) {
63 | for (i = 0; i < tex.Width; ++i) {
64 | tex256[i + j * tex.Width] = j ^ i;
65 | }
66 | }
67 |
68 | GSPRIMUVPOINT *verts = (GSPRIMUVPOINT*)malloc(sizeof(GSPRIMUVPOINT) * totalVertices);
69 | verts[0].xyz2 = vertex_to_XYZ2(gsGlobal, 0, 0, 0);
70 | verts[0].rgbaq = color;
71 | verts[0].uv = vertex_to_UV(&tex, 0, 0);
72 |
73 | verts[1].xyz2 = vertex_to_XYZ2(gsGlobal, gsGlobal->Width, gsGlobal->Height, 0);
74 | verts[1].rgbaq = color;
75 | verts[1].uv = vertex_to_UV(&tex, tex.Width, tex.Height);
76 |
77 | offset = 0;
78 |
79 | while(1) {
80 | unsigned int* clut = tex.Clut;
81 | for (i = 0; i < CLUT_SIZE; ++i) {
82 | unsigned int j = (i + offset)&0xff;
83 | *(clut++) = (j << 24)|(j << 16)|(j << 8)|(j);
84 | }
85 |
86 | gsKit_clear(gsGlobal, White);
87 | gsKit_TexManager_invalidate(gsGlobal, &tex);
88 | gsKit_TexManager_bind(gsGlobal, &tex);
89 | gskit_prim_list_sprite_texture_uv_3d(gsGlobal, &tex, totalVertices, verts);
90 |
91 | gsKit_queue_exec(gsGlobal);
92 | gsKit_sync_flip(gsGlobal);
93 | gsKit_TexManager_nextFrame(gsGlobal);
94 |
95 | offset++;
96 | }
97 |
98 | free(verts);
99 |
100 | return 0;
101 | }
102 |
--------------------------------------------------------------------------------
/examples/clutcsm/clutcsm.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // textures.c - Example demonstrating how the 2 different CLUT storage modes work.
10 | // CSMT1 and CSM1 are the two different CLUT storage modes. CSM1 is the default
11 | // mode, and is the mode that is used which requires to have the content swizzled
12 | // before uploading it to the GS. However, CSM2 is a mode that allows you to
13 | // upload the CLUT data directly to the GS, without having to swizzle it first.
14 | // Additionally it allows you to upload a list of CLUTs, and then switch between
15 | // them using the GS_SETCLUT command.
16 | //
17 | //
18 |
19 | #include
20 | #include
21 |
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #define CLUT_SIZE 256
29 | #define TEXTURE_WIDTH 320
30 | #define TEXTURE_HEIGHT 240
31 |
32 | #define USING_CSM1 0
33 |
34 | #if USING_CSM1
35 | #define TEXTURE_CLUT_WIDTH 16
36 | #define TEXTURE_CLUT_HEIGHT 16
37 | #else
38 | #define TEXTURE_CLUT_WIDTH 256
39 | #define TEXTURE_CLUT_HEIGHT 1
40 | #endif
41 |
42 | int main(int argc, char *argv[])
43 | {
44 | GSGLOBAL *gsGlobal;
45 | GSTEXTURE tex;
46 | uint32_t i, j, offset;
47 | uint32_t totalVertices = 2;
48 | uint64_t White = GS_SETREG_RGBAQ(0xFF, 0xFF, 0xFF, 0x00, 0x00);
49 | gs_rgbaq color = color_to_RGBAQ(0x80, 0x80, 0x80, 0x80, 0);
50 |
51 | gsGlobal = gsKit_init_global();
52 |
53 | gsGlobal->PSM = GS_PSM_CT24;
54 | gsGlobal->PSMZ = GS_PSMZ_16S;
55 |
56 | dmaKit_init(D_CTRL_RELE_OFF, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
57 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
58 |
59 | // Initialize the DMAC
60 | dmaKit_chan_init(DMA_CHANNEL_GIF);
61 |
62 | gsKit_init_screen(gsGlobal);
63 | gsKit_mode_switch(gsGlobal, GS_ONESHOT);
64 |
65 | tex.Width = TEXTURE_WIDTH;
66 | tex.Height = TEXTURE_HEIGHT;
67 | tex.PSM = GS_PSM_T8;
68 | tex.ClutPSM = GS_PSM_CT16;
69 | tex.Clut = memalign(128, gsKit_texture_size_ee(CLUT_SIZE, 1, tex.ClutPSM));
70 | tex.Mem = memalign(128, gsKit_texture_size_ee(tex.Width, tex.Height, tex.PSM));
71 | tex.Vram = gsKit_vram_alloc(gsGlobal, gsKit_texture_size(tex.Width, tex.Height, GS_PSM_T8), GSKIT_ALLOC_USERBUFFER);
72 | tex.VramClut = gsKit_vram_alloc(gsGlobal, gsKit_texture_size(TEXTURE_CLUT_WIDTH, TEXTURE_CLUT_HEIGHT, GS_PSM_CT16), GSKIT_ALLOC_USERBUFFER);
73 | #if USING_CSM1
74 | tex.ClutStorageMode = GS_CLUT_STORAGE_CSM1;
75 | #else
76 | tex.ClutStorageMode = GS_CLUT_STORAGE_CSM2;
77 | #endif
78 |
79 | printf("Tex VRAM Range = 0x%X - 0x%X\n", tex.Vram, tex.Vram + gsKit_texture_size(tex.Width, tex.Height, tex.PSM) - 1);
80 |
81 | gsKit_set_clamp(gsGlobal, GS_CMODE_CLAMP);
82 |
83 | uint16_t colors[4] = {
84 | 0xEFFF,
85 | 0x001F,
86 | 0x03E0,
87 | 0x7C00,
88 | };
89 |
90 | // fill the clut, each 16 positions are the same color
91 | uint16_t *clut = (uint16_t *)tex.Clut;
92 | for (i = 0; i < CLUT_SIZE; i += 16)
93 | {
94 | for (j = 0; j < 16; ++j)
95 | {
96 | clut[i + j] = colors[(i / 16) & 0x3];
97 | }
98 | }
99 | #if USING_CSM1
100 | // Swap the texture to have the CSM1 requirements
101 | for (i = 0; i < CLUT_SIZE; i++)
102 | {
103 | if ((i & 0x18) == 8)
104 | {
105 | uint16_t tmp = clut[i];
106 | clut[i] = clut[i + 8];
107 | clut[i + 8] = tmp;
108 | }
109 | }
110 | #endif
111 |
112 | // print the clut, 16 colors per line
113 | for (i = 0; i < CLUT_SIZE; i += 16)
114 | {
115 | for (j = 0; j < 16; ++j)
116 | {
117 | printf("%04X ", clut[i + j]);
118 | }
119 | printf("\n");
120 | }
121 |
122 | // initialize texture, each 16 horizontal pixels are the same color, so let's point to the right color
123 | uint8_t *tex256 = (uint8_t *)tex.Mem;
124 | for (i = 0; i < TEXTURE_HEIGHT; ++i)
125 | {
126 | for (j = 0; j < TEXTURE_WIDTH; ++j)
127 | {
128 | tex256[i * TEXTURE_WIDTH + j] = j & 0xFF;
129 | }
130 | }
131 |
132 | gsKit_texture_send((u32 *)tex.Mem, tex.Width, tex.Height, tex.Vram, tex.PSM, 1, GS_CLUT_TEXTURE);
133 | gsKit_texture_send((u32 *)tex.Clut, TEXTURE_CLUT_WIDTH, TEXTURE_CLUT_HEIGHT, tex.VramClut, tex.ClutPSM, 1, GS_CLUT_PALLETE);
134 |
135 | GSPRIMUVPOINTFLAT *verts = (GSPRIMUVPOINTFLAT *)malloc(sizeof(GSPRIMUVPOINTFLAT) * totalVertices);
136 | verts[0].xyz2 = vertex_to_XYZ2(gsGlobal, 0, 0, 0);
137 | verts[0].uv = vertex_to_UV(&tex, 0, 0);
138 |
139 | verts[1].xyz2 = vertex_to_XYZ2(gsGlobal, gsGlobal->Width, gsGlobal->Height, 0);
140 | verts[1].uv = vertex_to_UV(&tex, tex.Width, tex.Height);
141 |
142 | offset = 0;
143 |
144 | gs_texclut texclut = postion_to_TEXCLUT(4, 0, 0);
145 |
146 | while (1)
147 | {
148 | gsKit_clear(gsGlobal, White);
149 | #if !USING_CSM1
150 | gsKit_set_texclut(gsGlobal, texclut);
151 | #endif
152 | gskit_prim_list_sprite_texture_uv_flat_color(gsGlobal, &tex, color, totalVertices, verts);
153 |
154 | gsKit_queue_exec(gsGlobal);
155 | gsKit_sync_flip(gsGlobal);
156 |
157 | offset++;
158 | }
159 |
160 | free(verts);
161 |
162 | return 0;
163 | }
164 |
--------------------------------------------------------------------------------
/examples/coverflow/coverflow.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2017 - Rick "Maximus32" Gaiser
6 | // Copyright 2004 - Chris "Neovanglist" Gilbert
7 | // Licenced under Academic Free License version 2.0
8 | // Review gsKit README & LICENSE files for further details.
9 | //
10 | // coverflow.c - Example demonstrating gsKit texture manager.
11 | //
12 |
13 | #include
14 | #include
15 |
16 | #include
17 | #include
18 | #include
19 |
20 |
21 | // DVD cover size: 129x184mm
22 | #define COVER_HEIGHT (450.0f)
23 | #define COVER_WIDTH (COVER_HEIGHT*129.0f/184.0f)
24 | const float fCoverHeight = COVER_HEIGHT;
25 | const float fCoverWidth = COVER_WIDTH;
26 | const float fCoverDistance = COVER_WIDTH + 25.0f;
27 |
28 | #define TEXTURE_COUNT 5
29 |
30 |
31 | void drawCover(GSGLOBAL *gsGlobal, GSTEXTURE * tex, float fx, float fy)
32 | {
33 | u64 TexCol1 = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
34 | u64 TexCol2 = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x20,0x00);
35 |
36 | gsKit_TexManager_bind(gsGlobal, tex);
37 |
38 | // Draw normal
39 | gsKit_prim_sprite_texture(gsGlobal, tex,
40 | fx, // X1
41 | fy - fCoverHeight, // Y2
42 | 0.0f, // U1
43 | 0.0f, // V1
44 | fx + fCoverWidth, // X2
45 | fy, // Y2
46 | tex->Width, // U2
47 | tex->Height, // V2
48 | 2,
49 | TexCol1);
50 |
51 | // Draw upside down
52 | gsKit_prim_sprite_texture(gsGlobal, tex,
53 | fx, // X1
54 | fy + fCoverHeight, // Y2
55 | 0.0f, // U1
56 | 0.0f, // V1
57 | fx + fCoverWidth, // X2
58 | fy, // Y2
59 | tex->Width, // U2
60 | tex->Height, // V2
61 | 2,
62 | TexCol2);
63 | }
64 |
65 | int main(int argc, char *argv[])
66 | {
67 | GSGLOBAL *gsGlobal;
68 | GSTEXTURE Tex[TEXTURE_COUNT];
69 | u64 Black = GS_SETREG_RGBAQ(0x00,0x00,0x00,0x80,0x00);
70 | int iPassCount;
71 | float fXOff = 0.0;
72 | float fXOffCover;
73 | int iCoverStart = 0;
74 | int i;
75 | char filename[80];
76 |
77 | gsGlobal = gsKit_init_global();
78 |
79 | printf("\n");
80 | printf("--------------------------------------------------------------------------------\n");
81 | printf("------------------------------- !!! WARNING !!! --------------------------------\n");
82 | printf("--------------------------------------------------------------------------------\n");
83 | printf("- -\n");
84 | printf("- This example uses 'HIRES': -\n");
85 | printf("- -\n");
86 | printf("- HIRES saves VRAM by having only the part of the frame -\n");
87 | printf("- in VRAM that is currently being read by the CRTC. -\n");
88 | printf("- -\n");
89 | printf("- Use it on a REAL PS2! -\n");
90 | printf("- On an emulator (PCSX2), you will only see part of the screen. -\n");
91 | printf("- -\n");
92 | printf("--------------------------------------------------------------------------------\n");
93 | printf("\n");
94 |
95 | gsGlobal->Mode = GS_MODE_DTV_720P;
96 | gsGlobal->Interlace = GS_NONINTERLACED;
97 | gsGlobal->Field = GS_FRAME;
98 | gsGlobal->Width = 1280;
99 | gsGlobal->Height = 720;
100 | iPassCount = 3;
101 |
102 | gsGlobal->PSM = GS_PSM_CT16S;
103 | gsGlobal->PSMZ = GS_PSMZ_16S;
104 | gsGlobal->Dithering = GS_SETTING_ON;
105 | gsGlobal->DoubleBuffering = GS_SETTING_ON;
106 | gsGlobal->ZBuffering = GS_SETTING_ON;
107 |
108 | dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
109 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
110 |
111 | // Initialize the DMAC
112 | dmaKit_chan_init(DMA_CHANNEL_GIF);
113 |
114 | gsKit_hires_init_screen(gsGlobal, iPassCount);
115 |
116 | // Load textures
117 | for (i = 0; i < TEXTURE_COUNT; i++) {
118 | Tex[i].Delayed = 1;
119 | snprintf(filename, 80, "host:covers/game%d_%d_%d_08bit.bmp", i+1, 512, 512);
120 | gsKit_texture_bmp(gsGlobal, &Tex[i], filename);
121 | Tex[i].Filter = GS_FILTER_LINEAR;
122 | }
123 |
124 | // Clear static loaded textures, use texture manager instead
125 | gsKit_vram_clear(gsGlobal);
126 |
127 | gsKit_set_clamp(gsGlobal, GS_CMODE_CLAMP);
128 |
129 | gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 128), 0);
130 | gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
131 |
132 | while(1)
133 | {
134 | int iCover;
135 |
136 | gsKit_clear(gsGlobal, Black);
137 |
138 | // Draw coverflow
139 | iCover = iCoverStart;
140 | for (fXOffCover = fXOff; fXOffCover < gsGlobal->Width; fXOffCover += fCoverDistance) {
141 | drawCover(gsGlobal, &Tex[iCover], fXOffCover, (gsGlobal->Height/4)*3);
142 | iCover = iCover >= (TEXTURE_COUNT-1) ? 0 : iCover+1;
143 | }
144 |
145 | // Advance coverflow
146 | fXOff -= 5.0f;
147 | if (fXOff <= -fCoverDistance) {
148 | fXOff += fCoverDistance;
149 | iCoverStart = iCoverStart >= (TEXTURE_COUNT-1) ? 0 : iCoverStart+1;
150 | }
151 |
152 | gsKit_hires_sync(gsGlobal);
153 | gsKit_hires_flip(gsGlobal);
154 | gsKit_TexManager_nextFrame(gsGlobal);
155 | }
156 |
157 | return 0;
158 | }
159 |
--------------------------------------------------------------------------------
/examples/coverflow/covers/game1_512_512_08bit.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/coverflow/covers/game1_512_512_08bit.bmp
--------------------------------------------------------------------------------
/examples/coverflow/covers/game2_512_512_08bit.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/coverflow/covers/game2_512_512_08bit.bmp
--------------------------------------------------------------------------------
/examples/coverflow/covers/game3_512_512_08bit.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/coverflow/covers/game3_512_512_08bit.bmp
--------------------------------------------------------------------------------
/examples/coverflow/covers/game4_512_512_08bit.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/coverflow/covers/game4_512_512_08bit.bmp
--------------------------------------------------------------------------------
/examples/coverflow/covers/game5_512_512_08bit.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/coverflow/covers/game5_512_512_08bit.bmp
--------------------------------------------------------------------------------
/examples/cube/cube.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2022 - Daniel Santos
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // cube.c - Example demonstrating gsKit 3D with triangle list operation.
10 | //
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 | #include
19 | #include
20 | #include
21 |
22 | #include
23 | #include
24 |
25 | #include "mesh_data.c"
26 |
27 | static const u64 BLACK_RGBAQ = GS_SETREG_RGBAQ(0x00,0x00,0x00,0x80,0x00);
28 |
29 | VECTOR object_position = { 0.00f, 0.00f, 0.00f, 1.00f };
30 | VECTOR object_rotation = { 0.00f, 0.00f, 0.00f, 1.00f };
31 |
32 | VECTOR camera_position = { 0.00f, 0.00f, 100.00f, 1.00f };
33 | VECTOR camera_rotation = { 0.00f, 0.00f, 0.00f, 1.00f };
34 |
35 | void flipScreen(GSGLOBAL* gsGlobal)
36 | {
37 | gsKit_queue_exec(gsGlobal);
38 | gsKit_sync_flip(gsGlobal);
39 | }
40 |
41 | GSGLOBAL* init_graphics()
42 | {
43 | GSGLOBAL* gsGlobal = gsKit_init_global();
44 |
45 | gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
46 | //gsGlobal->PrimAAEnable = GS_SETTING_ON;
47 |
48 | gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 0), 0);
49 |
50 | dmaKit_init(D_CTRL_RELE_OFF, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
51 | dmaKit_chan_init(DMA_CHANNEL_GIF);
52 |
53 | gsKit_set_clamp(gsGlobal, GS_CMODE_REPEAT);
54 |
55 | gsKit_vram_clear(gsGlobal);
56 |
57 | gsKit_init_screen(gsGlobal);
58 |
59 | gsKit_mode_switch(gsGlobal, GS_ONESHOT);
60 |
61 | return gsGlobal;
62 |
63 | }
64 |
65 | int gsKit_convert_xyz(vertex_f_t *output, GSGLOBAL* gsGlobal, int count, vertex_f_t *vertices)
66 | {
67 |
68 | int z;
69 | unsigned int max_z;
70 |
71 | switch(gsGlobal->PSMZ){
72 | case GS_PSMZ_32:
73 | z = 32;
74 | break;
75 |
76 | case GS_PSMZ_24:
77 | z = 24;
78 | break;
79 |
80 | case GS_PSMZ_16:
81 | case GS_PSMZ_16S:
82 | z = 16;
83 | break;
84 |
85 | default:
86 | return -1;
87 | }
88 |
89 | float center_x = gsGlobal->Width/2;
90 | float center_y = gsGlobal->Height/2;
91 | max_z = 1 << (z - 1);
92 |
93 | for (int i = 0; i < count; i++)
94 | {
95 | output[i].x = ((vertices[i].x + 1.0f) * center_x);
96 | output[i].y = ((vertices[i].y + 1.0f) * center_y);
97 | output[i].z = (unsigned int)((vertices[i].z + 1.0f) * max_z);
98 | }
99 |
100 | // End function.
101 | return 0;
102 |
103 | }
104 |
105 | int render(GSGLOBAL* gsGlobal)
106 | {
107 |
108 | // Matrices to setup the 3D environment and camera
109 | MATRIX local_world;
110 | MATRIX world_view;
111 | MATRIX view_screen;
112 | MATRIX local_screen;
113 |
114 | VECTOR *temp_vertices;
115 |
116 | VECTOR *verts;
117 | color_t *colors;
118 |
119 | GSPRIMPOINT *gs_vertices = (GSPRIMPOINT *)memalign(128, sizeof(GSPRIMPOINT) * points_count);
120 |
121 | VECTOR *c_verts = (VECTOR *)memalign(128, sizeof(VECTOR) * points_count);
122 | VECTOR* c_colours = (VECTOR *)memalign(128, sizeof(VECTOR) * points_count);
123 |
124 |
125 | for (int i = 0; i < points_count; i++)
126 | {
127 | c_verts[i][0] = vertices[points[i]][0];
128 | c_verts[i][1] = vertices[points[i]][1];
129 | c_verts[i][2] = vertices[points[i]][2];
130 | c_verts[i][3] = vertices[points[i]][3];
131 |
132 | c_colours[i][0] = colours[points[i]][0];
133 | c_colours[i][1] = colours[points[i]][1];
134 | c_colours[i][2] = colours[points[i]][2];
135 | c_colours[i][3] = colours[points[i]][3];
136 | }
137 |
138 | // Allocate calculation space.
139 | temp_vertices = memalign(128, sizeof(VECTOR) * points_count);
140 |
141 | // Allocate register space.
142 | verts = memalign(128, sizeof(VECTOR) * points_count);
143 | colors = memalign(128, sizeof(color_t) * points_count);
144 |
145 | // Create the view_screen matrix.
146 | create_view_screen(view_screen, 4.0f/3.0f, -0.5f, 0.5f, -0.5f, 0.5f, 1.00f, 2000.00f);
147 |
148 | if (gsGlobal->ZBuffering == GS_SETTING_ON)
149 | gsKit_set_test(gsGlobal, GS_ZTEST_ON);
150 |
151 | gsGlobal->PrimAAEnable = GS_SETTING_ON;
152 |
153 | // The main loop...
154 | for (;;)
155 | {
156 |
157 | // Spin the cube a bit.
158 | object_rotation[0] += 0.008f; //while (object_rotation[0] > 3.14f) { object_rotation[0] -= 6.28f; }
159 | object_rotation[1] += 0.012f; //while (object_rotation[1] > 3.14f) { object_rotation[1] -= 6.28f; }
160 |
161 | // Create the local_world matrix.
162 | create_local_world(local_world, object_position, object_rotation);
163 |
164 | // Create the world_view matrix.
165 | create_world_view(world_view, camera_position, camera_rotation);
166 |
167 | // Create the local_screen matrix.
168 | create_local_screen(local_screen, local_world, world_view, view_screen);
169 |
170 | // Calculate the vertex values.
171 | calculate_vertices(temp_vertices, points_count, c_verts, local_screen);
172 |
173 | // Convert floating point vertices to fixed point and translate to center of screen.
174 | gsKit_convert_xyz((vertex_f_t*)verts, gsGlobal, points_count, (vertex_f_t*)temp_vertices);
175 |
176 | // Convert floating point colours to fixed point.
177 | draw_convert_rgbq(colors, points_count, (vertex_f_t*)temp_vertices, (color_f_t*)c_colours, 0x80);
178 |
179 | for (int i = 0; i < points_count; i++)
180 | {
181 | gs_vertices[i].rgbaq = color_to_RGBAQ(colors[i].r, colors[i].g, colors[i].b, colors[i].a, 0.0f);
182 | gs_vertices[i].xyz2 = vertex_to_XYZ2(gsGlobal, verts[i][0], verts[i][1], verts[i][2]);
183 | }
184 |
185 | gsKit_clear(gsGlobal, BLACK_RGBAQ);
186 |
187 | gsKit_prim_list_triangle_gouraud_3d(gsGlobal, points_count, gs_vertices);
188 |
189 | flipScreen(gsGlobal);
190 |
191 | }
192 |
193 | return 0;
194 |
195 | }
196 |
197 | int main(int argc, char *argv[])
198 | {
199 |
200 | // Init GS.
201 | GSGLOBAL* gsGlobal = init_graphics();
202 |
203 | // Render the cube
204 | render(gsGlobal);
205 |
206 | // Sleep
207 | SleepThread();
208 |
209 | // End program.
210 | return 0;
211 |
212 | }
213 |
--------------------------------------------------------------------------------
/examples/cube/mesh_data.c:
--------------------------------------------------------------------------------
1 | /*
2 | # _____ ___ ____ ___ ____
3 | # ____| | ____| | | |____|
4 | # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 | #-----------------------------------------------------------------------
6 | # (c) 2005 Naomi Peori
7 | # Licenced under Academic Free License version 2.0
8 | # Review ps2sdk README & LICENSE files for further details.
9 | #
10 | */
11 |
12 | int points_count = 36;
13 |
14 | int points[36] = {
15 | 0, 1, 2,
16 | 1, 2, 3,
17 | 4, 5, 6,
18 | 5, 6, 7,
19 | 8, 9, 10,
20 | 9, 10, 11,
21 | 12, 13, 14,
22 | 13, 14, 15,
23 | 16, 17, 18,
24 | 17, 18, 19,
25 | 20, 21, 22,
26 | 21, 22, 23
27 | };
28 |
29 | int vertex_count = 24;
30 |
31 | VECTOR vertices[24] = {
32 | { 10.00f, 10.00f, 10.00f, 1.00f },
33 | { 10.00f, 10.00f, -10.00f, 1.00f },
34 | { 10.00f, -10.00f, 10.00f, 1.00f },
35 | { 10.00f, -10.00f, -10.00f, 1.00f },
36 | { -10.00f, 10.00f, 10.00f, 1.00f },
37 | { -10.00f, 10.00f, -10.00f, 1.00f },
38 | { -10.00f, -10.00f, 10.00f, 1.00f },
39 | { -10.00f, -10.00f, -10.00f, 1.00f },
40 | { -10.00f, 10.00f, 10.00f, 1.00f },
41 | { 10.00f, 10.00f, 10.00f, 1.00f },
42 | { -10.00f, 10.00f, -10.00f, 1.00f },
43 | { 10.00f, 10.00f, -10.00f, 1.00f },
44 | { -10.00f, -10.00f, 10.00f, 1.00f },
45 | { 10.00f, -10.00f, 10.00f, 1.00f },
46 | { -10.00f, -10.00f, -10.00f, 1.00f },
47 | { 10.00f, -10.00f, -10.00f, 1.00f },
48 | { -10.00f, 10.00f, 10.00f, 1.00f },
49 | { 10.00f, 10.00f, 10.00f, 1.00f },
50 | { -10.00f, -10.00f, 10.00f, 1.00f },
51 | { 10.00f, -10.00f, 10.00f, 1.00f },
52 | { -10.00f, 10.00f, -10.00f, 1.00f },
53 | { 10.00f, 10.00f, -10.00f, 1.00f },
54 | { -10.00f, -10.00f, -10.00f, 1.00f },
55 | { 10.00f, -10.00f, -10.00f, 1.00f }
56 | };
57 |
58 | VECTOR colours[24] = {
59 | { 1.00f, 0.00f, 0.00f, 1.00f },
60 | { 1.00f, 0.00f, 0.00f, 1.00f },
61 | { 1.00f, 0.00f, 0.00f, 1.00f },
62 | { 1.00f, 0.00f, 0.00f, 1.00f },
63 | { 1.00f, 0.00f, 0.00f, 1.00f },
64 | { 1.00f, 0.00f, 0.00f, 1.00f },
65 | { 1.00f, 0.00f, 0.00f, 1.00f },
66 | { 1.00f, 0.00f, 0.00f, 1.00f },
67 | { 0.00f, 1.00f, 0.00f, 1.00f },
68 | { 0.00f, 1.00f, 0.00f, 1.00f },
69 | { 0.00f, 1.00f, 0.00f, 1.00f },
70 | { 0.00f, 1.00f, 0.00f, 1.00f },
71 | { 0.00f, 1.00f, 0.00f, 1.00f },
72 | { 0.00f, 1.00f, 0.00f, 1.00f },
73 | { 0.00f, 1.00f, 0.00f, 1.00f },
74 | { 0.00f, 1.00f, 0.00f, 1.00f },
75 | { 0.00f, 0.00f, 1.00f, 1.00f },
76 | { 0.00f, 0.00f, 1.00f, 1.00f },
77 | { 0.00f, 0.00f, 1.00f, 1.00f },
78 | { 0.00f, 0.00f, 1.00f, 1.00f },
79 | { 0.00f, 0.00f, 1.00f, 1.00f },
80 | { 0.00f, 0.00f, 1.00f, 1.00f },
81 | { 0.00f, 0.00f, 1.00f, 1.00f },
82 | { 0.00f, 0.00f, 1.00f, 1.00f }
83 | };
84 |
--------------------------------------------------------------------------------
/examples/fb/bsdgirl.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/fb/bsdgirl.bmp
--------------------------------------------------------------------------------
/examples/fb/fb.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // fb.c - Example demonstrating advanced effects and CLUT usage.
10 | // Special thanks to "gawd^" for this file! He wrote it, and it was used
11 | // to help debug a really crappy CLUT/texturing bug!
12 | //
13 |
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 |
21 | #include
22 |
23 | #define USEBMP
24 |
25 | static void generate_palette(GSTEXTURE *tex)
26 | {
27 | int i;
28 | u32 *cptr;
29 |
30 | cptr = (u32 *)tex->Clut;
31 |
32 | for (i=0; i<128; i++)
33 | {
34 | /* 128 shades of red followed by 128 shades of yellow */
35 | cptr[i] = (i << 1);
36 | cptr[i+128] = ((i << 1) << 8) | 0xff;
37 | }
38 | }
39 | /*
40 | static void generate_framex(GSTEXTURE *tex)
41 | {
42 | int x, y;
43 | unsigned char *pixels, c;
44 |
45 | pixels = (unsigned char *)tex->Mem;
46 | for (y=0; y < tex->Height; y++)
47 | {
48 | c = (unsigned char)(255.0 * y / tex->Height);
49 | for (x=0; x < tex->Width; x++)
50 | {
51 | *pixels++ = c;
52 | }
53 | }
54 | }
55 | */
56 | static void generate_frame(GSTEXTURE *tex)
57 | {
58 | int x, y;
59 | int stride;
60 | int a, b, c, d;
61 | int color;
62 | unsigned char *pixels;
63 |
64 | stride = tex->Width;
65 | pixels = (unsigned char *)tex->Mem;
66 |
67 | /* randominze last line */
68 | for (x=1; xWidth; x++)
69 | {
70 | pixels[(tex->Height-1) * stride + x] = (rand() & 0xff);
71 | }
72 |
73 | /* soften */
74 | for (x=1; xWidth-1; x++)
75 | {
76 | for (y=0; y < tex->Height-1; y++)
77 | {
78 | a = pixels[(y+1)*stride + x - 1];
79 | b = pixels[(y+1)*stride + x + 0];
80 | c = pixels[(y+1)*stride + x + 1];
81 | d = pixels[(y+2)*stride + x + 0];
82 | color = (a + b + c + d) / 4;
83 |
84 | if ((color > 0) && (color < 128))
85 | {
86 | /* fade */
87 | color--;
88 | }
89 |
90 | pixels[y*stride + x] = color;
91 | }
92 | }
93 | }
94 |
95 | int main(int argc, char *argv[])
96 | {
97 | #ifdef USEBMP
98 | GSTEXTURE backtex;
99 | #endif
100 | GSTEXTURE fb;
101 | GSGLOBAL *gsGlobal;
102 |
103 | /* initialize dmaKit */
104 | dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
105 |
106 | dmaKit_chan_init(DMA_CHANNEL_GIF);
107 |
108 | /* allocate GSGLOBAL structure */
109 | gsGlobal = gsKit_init_global();
110 |
111 | /* initialize screen */
112 | gsGlobal->PSM = GS_PSM_CT24;
113 | gsGlobal->ZBuffering = GS_SETTING_OFF; /* spare some vram */
114 | // If we disable double buffering, we can't fill the frame fast enough.
115 | // When this happens, we get a line through the top texture about 20% up
116 | // from the bottom of the screen.
117 | // gsGlobal->DoubleBuffering = GS_SETTING_OFF; /* only one screen */
118 | gsKit_init_screen(gsGlobal);
119 |
120 | gsKit_mode_switch(gsGlobal, GS_PERSISTENT);
121 |
122 | fb.Width = 320;
123 | fb.Height = 200;
124 | fb.PSM = GS_PSM_T8;
125 | fb.ClutPSM = GS_PSM_CT32;
126 |
127 | fb.Mem = memalign(128, gsKit_texture_size_ee(fb.Width, fb.Height, fb.PSM));
128 | fb.Clut = memalign(128, gsKit_texture_size_ee(16, 16, fb.ClutPSM));
129 |
130 | fb.VramClut = gsKit_vram_alloc(gsGlobal, gsKit_texture_size(16, 16, fb.ClutPSM), GSKIT_ALLOC_USERBUFFER);
131 | fb.Vram = gsKit_vram_alloc(gsGlobal, gsKit_texture_size(fb.Width, fb.Height, fb.PSM), GSKIT_ALLOC_USERBUFFER);
132 |
133 | fb.Filter = GS_FILTER_LINEAR; /* enable bilinear filtering */
134 |
135 | gsKit_setup_tbw(&fb);
136 |
137 | generate_palette(&fb);
138 |
139 | #ifdef USEBMP
140 | backtex.Delayed = 0;
141 | gsKit_texture_bmp(gsGlobal, &backtex, "host:bsdgirl.bmp");
142 | #endif
143 |
144 | /* print out useless debug information */
145 | printf("CLUT Texture:\n");
146 | printf("\tHost start: 0x%08x, end: 0x%08x\n", (unsigned)fb.Mem, (unsigned)(gsKit_texture_size_ee(fb.Width, fb.Height, fb.PSM) + fb.Mem));
147 | printf("\tLocal start: 0x%08x, end: 0x%08x\n", (unsigned)fb.Vram, (unsigned)(gsKit_texture_size(fb.Width, fb.Height, fb.PSM) + fb.Vram));
148 | printf("\tWidth - %d : Height - %d : TBW - %d : Page - %d : Block %d\n", fb.Width, fb.Height, fb.TBW, (fb.Vram / 8192), (fb.Vram / 256));
149 | printf("CLUT Pallete:\n");
150 | printf("\tHost start: 0x%08x, end: 0x%08x\n", (unsigned)fb.Clut, (unsigned)(gsKit_texture_size_ee(16, 16, GS_PSM_CT32) + fb.Clut));
151 | printf("\tLocal start: 0x%08x, end: 0x%08x\n", (unsigned)fb.VramClut, (unsigned)(gsKit_texture_size(16, 16, GS_PSM_CT32) + fb.VramClut));
152 | printf("\tWidth - %d : Height - %d : TBW - %d : Page - %d : Block %d\n", 16, 16, 1, (fb.VramClut / 8192), (fb.VramClut / 256));
153 | #ifdef USEBMP
154 | printf("BMP Texture:\n");
155 | printf("\tHost start: 0x%08x, end: 0x%08x\n", (unsigned)backtex.Mem, (unsigned)(gsKit_texture_size_ee(backtex.Width, backtex.Height, backtex.PSM) + backtex.Mem));
156 | printf("\tLocal start: 0x%08x, end: 0x%08x\n", (unsigned)backtex.Vram, (unsigned)(gsKit_texture_size(backtex.Width, backtex.Height, backtex.PSM) + backtex.Vram));
157 | printf("\tWidth - %d : Height - %d : TBW - %d : Page - %d : Block %d\n", backtex.Width, backtex.Height, backtex.TBW, (backtex.Vram / 8192), (backtex.Vram / 256));
158 | #endif
159 | printf("VRAM Alignment Check - Value of \"0\" is OKAY! Anything else is BAD!\n");
160 | printf("VRAM - CLUT Pallete - Start Address Aligned: %d\n", fb.VramClut % GS_VRAM_BLOCKSIZE_256);
161 | printf("VRAM - CLUT Texture - Start Address Aligned: %d\n", fb.Vram % GS_VRAM_BLOCKSIZE_256);
162 | #ifdef USEBMP
163 | printf("VRAM - BMP Texture - Start Address Aligned: %d\n", backtex.Vram % GS_VRAM_BLOCKSIZE_256);
164 | #endif
165 |
166 | /* clear buffer */
167 | gsKit_clear(gsGlobal, GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00));
168 |
169 | /* render frame buffer */
170 | gsKit_prim_sprite_texture( gsGlobal, &fb,
171 | 0.0f, /* X1 */
172 | 0.0f, /* Y1 */
173 | 0.0f, /* U1 */
174 | 0.0f, /* V1 */
175 | gsGlobal->Width, /* X2 */
176 | gsGlobal->Height, /* Y2 */
177 | fb.Width, /* U2 */
178 | fb.Height, /* V2*/
179 | 1, /* Z */
180 | GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00) /* RGBAQ */
181 | );
182 |
183 |
184 | #ifdef USEBMP
185 | gsKit_prim_sprite_texture(gsGlobal, &backtex,
186 | (gsGlobal->Width /2) - (backtex.Width / 2), /* X1 */
187 | 0.0f, /* Y1 */
188 | 0.0f, /* U1 */
189 | 0.0f, /* V1 */
190 | backtex.Width + ((gsGlobal->Width /2) - (backtex.Width / 2)), /* X2 */
191 | backtex.Height, /* Y2 */
192 | backtex.Width, /* U2 */
193 | backtex.Height, /* V2*/
194 | 2, /* Z */
195 | GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00) /* RGBAQ */
196 | );
197 | #endif
198 |
199 | while (1)
200 | {
201 | /* generate next frame */
202 | generate_frame(&fb);
203 |
204 | /* upload new frame buffer */
205 | gsKit_texture_upload(gsGlobal, &fb);
206 |
207 | /* execute render queue */
208 | gsKit_queue_exec(gsGlobal);
209 |
210 | /* vsync and flip buffer */
211 | gsKit_sync_flip(gsGlobal);
212 | }
213 |
214 | /* keep compilers happy (tm) */
215 | return 0;
216 | }
217 |
218 |
--------------------------------------------------------------------------------
/examples/fhdbg/fhdbg.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | #define TEXTURE_COUNT 3
8 |
9 | int main(int argc, char* argv[])
10 | {
11 | GSGLOBAL* gsGlobal;
12 | GSTEXTURE Tex[TEXTURE_COUNT];
13 | int iPassCount;
14 | int iTexId;
15 | char filename[80];
16 | int iFrameCount = 0;
17 |
18 | gsGlobal = gsKit_init_global();
19 |
20 | printf("\n");
21 | printf("--------------------------------------------------------------------------------\n");
22 | printf("------------------------------- !!! WARNING !!! --------------------------------\n");
23 | printf("--------------------------------------------------------------------------------\n");
24 | printf("- -\n");
25 | printf("- This example uses 'HIRES': -\n");
26 | printf("- -\n");
27 | printf("- HIRES saves VRAM by having only the part of the frame -\n");
28 | printf("- in VRAM that is currently being read by the CRTC. -\n");
29 | printf("- -\n");
30 | printf("- Use it on a REAL PS2! -\n");
31 | printf("- On an emulator (PCSX2), you will only see part of the screen. -\n");
32 | printf("- -\n");
33 | printf("--------------------------------------------------------------------------------\n");
34 | printf("\n");
35 |
36 | gsGlobal->Mode = GS_MODE_DTV_1080I;
37 | gsGlobal->Interlace = GS_INTERLACED;
38 | gsGlobal->Field = GS_FRAME;
39 | gsGlobal->Width = 1920;
40 | gsGlobal->Height = 540;
41 | iPassCount = 3;
42 |
43 | gsGlobal->PSM = GS_PSM_CT16S;
44 | gsGlobal->PSMZ = GS_PSMZ_16S;
45 | gsGlobal->Dithering = GS_SETTING_ON;
46 | gsGlobal->DoubleBuffering = GS_SETTING_ON;
47 | gsGlobal->ZBuffering = GS_SETTING_OFF;
48 |
49 | dmaKit_init(D_CTRL_RELE_OFF, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
50 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
51 |
52 | // Initialize the DMAC
53 | dmaKit_chan_init(DMA_CHANNEL_GIF);
54 |
55 | gsKit_hires_init_screen(gsGlobal, iPassCount);
56 |
57 | // Load textures
58 | for (iTexId = 0; iTexId < TEXTURE_COUNT; iTexId++) {
59 | Tex[iTexId].Delayed = 1;
60 | snprintf(filename, 80, "host:images/fhdbg_0%d.jpg", iTexId + 1);
61 | gsKit_texture_jpeg(gsGlobal, &Tex[iTexId], filename);
62 | gsKit_hires_prepare_bg(gsGlobal, &Tex[iTexId]);
63 | }
64 |
65 | iTexId = 0;
66 | gsKit_hires_set_bg(gsGlobal, &Tex[iTexId]);
67 |
68 | while (1) {
69 | // Wait for vsync
70 | gsKit_hires_sync(gsGlobal);
71 |
72 | // Next texture after 60 frames (1 second)
73 | iFrameCount++;
74 | if (iFrameCount >= 60) {
75 | iFrameCount = 0;
76 | iTexId++;
77 | if (iTexId >= TEXTURE_COUNT)
78 | iTexId = 0;
79 | gsKit_hires_set_bg(gsGlobal, &Tex[iTexId]);
80 | gsKit_hires_flip(gsGlobal);
81 | }
82 | }
83 |
84 | return 0;
85 | }
86 |
--------------------------------------------------------------------------------
/examples/fhdbg/images/fhdbg_01.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/fhdbg/images/fhdbg_01.jpg
--------------------------------------------------------------------------------
/examples/fhdbg/images/fhdbg_02.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/fhdbg/images/fhdbg_02.jpg
--------------------------------------------------------------------------------
/examples/fhdbg/images/fhdbg_03.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/fhdbg/images/fhdbg_03.jpg
--------------------------------------------------------------------------------
/examples/font/arial.fnt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/font/arial.fnt
--------------------------------------------------------------------------------
/examples/font/dejavu.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/font/dejavu.bmp
--------------------------------------------------------------------------------
/examples/font/dejavu.dat:
--------------------------------------------------------------------------------
1 | 0
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/examples/font/dejavu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/font/dejavu.png
--------------------------------------------------------------------------------
/examples/font/font.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // font.c - Example demonstrating basic font operation.
10 | //
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | #include
17 |
18 | int main(int argc, char *argv[])
19 | {
20 | u64 Black, WhiteFont, RedFont, GreenFont, BlueFont;
21 | GSGLOBAL *gsGlobal;
22 | GSFONT *gsFont;
23 |
24 | gsGlobal = gsKit_init_global();
25 |
26 | gsFont = gsKit_init_font(GSKIT_FTYPE_BMP_DAT, "host:dejavu.bmp");
27 | // gsFont = gsKit_init_font(GSKIT_FTYPE_PNG_DAT, "host:dejavu.png");
28 |
29 | dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
30 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
31 |
32 | // Initialize the DMAC
33 | dmaKit_chan_init(DMA_CHANNEL_GIF);
34 |
35 | Black = GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00);
36 | WhiteFont = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x80,0x00);
37 | RedFont = GS_SETREG_RGBAQ(0xFF,0x00,0x00,0x80,0x00);
38 | GreenFont = GS_SETREG_RGBAQ(0x00,0xFF,0x00,0x80,0x00);
39 | BlueFont = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x80,0x00);
40 |
41 | gsGlobal->PrimAlpha = GS_BLEND_FRONT2BACK;
42 | gsGlobal->PSM = GS_PSM_CT16;
43 | gsGlobal->PSMZ = GS_PSMZ_16;
44 |
45 | gsKit_init_screen(gsGlobal);
46 |
47 | gsKit_mode_switch(gsGlobal, GS_PERSISTENT);
48 |
49 | gsKit_font_upload(gsGlobal, gsFont);
50 |
51 | gsKit_clear(gsGlobal, Black);
52 |
53 | gsKit_font_print(gsGlobal, gsFont, 50, 50, 1, WhiteFont, "Hello World!");
54 |
55 | gsKit_font_print(gsGlobal, gsFont, 50, 80, 1, RedFont, "red");
56 | gsKit_font_print(gsGlobal, gsFont, 50, 110, 1, GreenFont, "green");
57 | gsKit_font_print(gsGlobal, gsFont, 50, 140, 1, BlueFont, "blue");
58 |
59 | gsKit_font_print_scaled(gsGlobal, gsFont, 400, 160, 2, 2.0f, BlueFont, "scaled 1\n"\
60 | "scaled 2\n"\
61 | "scaled 3\n");
62 |
63 | gsKit_font_print(gsGlobal, gsFont, 100, 200, 2, WhiteFont, "Testing 1\n"\
64 | "Testing 2\n"\
65 | "Testing 3\n"\
66 | "Testing 4\n"\
67 | "Testing 5\n"\
68 | "Testing 6\n"\
69 | "Testing 7\n"\
70 | "Testing 8\n"\
71 | "Testing 9\n"\
72 | "Testing 10\n");
73 | while(1)
74 | {
75 | gsKit_queue_exec(gsGlobal);
76 | gsKit_sync_flip(gsGlobal);
77 | }
78 |
79 | return 0;
80 | }
81 |
--------------------------------------------------------------------------------
/examples/fontm/fontm.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // fontm.c - Example demonstrating ROM Font (FONTM) usage
10 | //
11 | // Early units (SCPH-1xxxx and DESR-xxxx) lacks this feature
12 |
13 | #include
14 | #include
15 |
16 | #include
17 | #include
18 | #include
19 |
20 | int main(int argc, char *argv[])
21 | {
22 | u64 White, Black, BlackFont, WhiteFont, RedFont, GreenFont, BlueFont, TexCol, BlueTrans, RedTrans, GreenTrans, WhiteTrans;
23 | GSGLOBAL *gsGlobal;
24 | // GS_MODE_PAL_I
25 | // GS_MODE_VGA_640_60
26 | GSTEXTURE test;
27 |
28 | GSFONTM *gsFontM;
29 |
30 | float x = 10;
31 | float y = 10;
32 | float width = 150;
33 | float height = 150;
34 |
35 | char tempstr[256];
36 |
37 | float VHeight;
38 |
39 | float x2;
40 | float y2;
41 |
42 | gsGlobal = gsKit_init_global();
43 |
44 | gsFontM = gsKit_init_fontm();
45 |
46 | dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
47 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
48 |
49 | // Initialize the DMAC
50 | dmaKit_chan_init(DMA_CHANNEL_GIF);
51 |
52 | Black = GS_SETREG_RGBAQ(0x00,0x00,0x00,0x80,0x00);
53 | White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x80,0x00);
54 |
55 | WhiteFont = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
56 | BlackFont = GS_SETREG_RGBAQ(0x00,0x00,0x00,0x80,0x00);
57 | RedFont = GS_SETREG_RGBAQ(0xFF,0x80,0x80,0x80,0x00);
58 | GreenFont = GS_SETREG_RGBAQ(0x80,0xFF,0x80,0x80,0x00);
59 | BlueFont = GS_SETREG_RGBAQ(0x80,0x80,0xFF,0x80,0x00);
60 | TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
61 |
62 | BlueTrans = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x40,0x00);
63 | RedTrans = GS_SETREG_RGBAQ(0xFF,0x00,0x00,0x60,0x00);
64 | GreenTrans = GS_SETREG_RGBAQ(0x00,0xFF,0x00,0x50,0x00);
65 | WhiteTrans = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x50,0x00);
66 |
67 | VHeight = gsGlobal->Height;
68 |
69 | x2 = (gsGlobal->Width - 10) - width;
70 | y2 = VHeight - 10 - height;
71 |
72 | gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
73 |
74 | gsKit_init_screen(gsGlobal);
75 |
76 | gsKit_fontm_upload(gsGlobal, gsFontM);
77 |
78 | gsFontM->Spacing = 0.95f;
79 |
80 | test.Delayed = 1;
81 | gsKit_texture_bmp(gsGlobal, &test, "host:test.bmp");
82 | test.Filter = GS_FILTER_LINEAR;
83 |
84 | gsKit_mode_switch(gsGlobal, GS_ONESHOT);
85 | gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 0), 0);
86 |
87 | while(1)
88 | {
89 | if( y <= 10 && (x + width) < (gsGlobal->Width - 10))
90 | x+=5;
91 | else if( (y + height) < (VHeight - 10) && (x + width) >= (gsGlobal->Width - 10) )
92 | y+=5;
93 | else if( (y + height) >= (VHeight - 10) && x > 10 )
94 | x-=5;
95 | else if( y > 10 && x <= 10 )
96 | y-=5;
97 |
98 | if( y2 <= 10 && (x2 + width) < (gsGlobal->Width - 10))
99 | x2+=5;
100 | else if( (y2 + height) < (VHeight - 10) && (x2 + width) >= (gsGlobal->Width - 10) )
101 | y2+=5;
102 | else if( (y2 + height) >= (VHeight - 10) && x2 > 10 )
103 | x2-=5;
104 | else if( y2 > 10 && x2 <= 10 )
105 | y2-=5;
106 |
107 | gsKit_clear(gsGlobal, White);
108 |
109 | gsKit_TexManager_bind(gsGlobal, &test);
110 | gsKit_prim_sprite_texture(gsGlobal, &test,
111 | 50.0f, 50.0f, 0.0f, 0.0f,
112 | gsGlobal->Width - 50.0f, gsGlobal->Height - 50.0f,
113 | test.Width, test.Height,
114 | 1, TexCol);
115 |
116 | gsKit_prim_sprite(gsGlobal, x2, y2, x2 + width, y2 + height, 2, RedTrans);
117 | gsKit_prim_sprite(gsGlobal, x2, y, x2 + width, y + height, 1, WhiteTrans);
118 |
119 | gsKit_fontm_print_scaled(gsGlobal, gsFontM, 50, 50, 3, 0.85f, WhiteFont,
120 | "1: ABCDEFGHIJKLM\n"
121 | "2: NOPQRSTUVWXYZ\n"
122 | "3: abcdefghijklm\n"
123 | "4: nopqrstuvwxyz\n"
124 | "5: 1234567890,./`\n"
125 | "6: ~!@#$%^&*()_<>\n"
126 | "7: +-=[]{}\\|;:\"'?\n"
127 | "8: \ele \ege \einf \emale \efemale \edegc \eyen \ecent \epound\n"
128 | "9: \eleft \eright \eup \edown \efleft \efright \efup \efdown\n"
129 | "10:\ehleft \ehright \ehup \ehdown \ems \eus \ens \edegf\n"
130 | "11:\embit \ehz \ekb \emb \egb \etb \f0855 \f0850");
131 |
132 | sprintf(tempstr, "X =%d\t| Y =%d\nX2=%d\t| Y2=%d", (int)x, (int)y, (int)x2, (int)y2);
133 |
134 | gsKit_fontm_print_scaled(gsGlobal, gsFontM, 50, 340, 3, 0.6f, RedFont, tempstr);
135 |
136 | // gsKit_font_print(gsGlobal, gsFont, 50, 50, 2.0f, TexCol, "\f0000");
137 |
138 | gsKit_prim_sprite(gsGlobal, 418, 335, 422, 425, 3, Black);
139 |
140 | gsKit_fontm_print_scaled(gsGlobal, gsFontM, 420, 340, 4, 0.6f, BlueFont, "Left Aligned");
141 | gsFontM->Align = GSKIT_FALIGN_CENTER;
142 | gsKit_fontm_print_scaled(gsGlobal, gsFontM, 420, 370, 4, 0.6f, GreenFont, "Center Aligned");
143 | gsFontM->Align = GSKIT_FALIGN_RIGHT;
144 | gsKit_fontm_print_scaled(gsGlobal, gsFontM, 420, 400, 4, 0.60f, BlackFont, "Right Aligned");
145 | gsFontM->Align = GSKIT_FALIGN_LEFT;
146 |
147 | gsKit_prim_sprite(gsGlobal, x, y, x + width, y + height, 4, BlueTrans);
148 | gsKit_prim_sprite(gsGlobal, x, y2, x + width, y2 + height, 3, GreenTrans);
149 |
150 | gsKit_queue_exec(gsGlobal);
151 | gsKit_sync_flip(gsGlobal);
152 | gsKit_TexManager_nextFrame(gsGlobal);
153 | }
154 |
155 | return 0;
156 | }
157 |
--------------------------------------------------------------------------------
/examples/fontm/test.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/fontm/test.bmp
--------------------------------------------------------------------------------
/examples/hires/bigtex.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/hires/bigtex.bmp
--------------------------------------------------------------------------------
/examples/hires/bigtex.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/hires/bigtex.jpg
--------------------------------------------------------------------------------
/examples/hires/fhdbg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/hires/fhdbg.jpg
--------------------------------------------------------------------------------
/examples/linuz-texture/testorig.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/linuz-texture/testorig.bmp
--------------------------------------------------------------------------------
/examples/linuz-texture/testorig.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/linuz-texture/testorig.jpg
--------------------------------------------------------------------------------
/examples/linuz-texture/testorig.ppm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/linuz-texture/testorig.ppm
--------------------------------------------------------------------------------
/examples/linuz-texture/texture.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // texture.c - Example demonstrating CLUT texture operation.
10 | //
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | extern char testorig[];
17 | extern u32 image_clut32[];
18 | extern u8 image_pixel[];
19 |
20 | int main(int argc, char *argv[])
21 | {
22 | u64 White, Black;
23 | GSTEXTURE tex;
24 | GSTEXTURE tex8;
25 | GSGLOBAL *gsGlobal = gsKit_init_global();
26 |
27 | dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
28 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
29 |
30 | // Initialize the DMAC
31 | dmaKit_chan_init(DMA_CHANNEL_GIF);
32 |
33 | White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
34 | Black = GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00);
35 |
36 | gsGlobal->PSM = GS_PSM_CT24;
37 |
38 | gsGlobal->ZBuffering = GS_SETTING_OFF;
39 |
40 | gsKit_init_screen(gsGlobal);
41 |
42 | gsKit_mode_switch(gsGlobal, GS_PERSISTENT);
43 |
44 | tex.Width = 256;
45 | tex.Height = 256;
46 | tex.PSM = GS_PSM_CT24;
47 | tex.Mem = (void *)testorig;
48 | tex.Vram = gsKit_vram_alloc(gsGlobal, gsKit_texture_size(tex.Width, tex.Height, tex.PSM), GSKIT_ALLOC_USERBUFFER);
49 | tex.Filter = GS_FILTER_LINEAR;
50 | gsKit_texture_upload(gsGlobal, &tex);
51 |
52 | tex8.Width = 256;
53 | tex8.Height = 256;
54 | tex8.PSM = GS_PSM_T8;
55 | tex8.Mem = (void *)image_pixel;
56 | tex8.Vram = gsKit_vram_alloc(gsGlobal, gsKit_texture_size(tex8.Width, tex8.Height, tex8.PSM), GSKIT_ALLOC_USERBUFFER);
57 | tex8.Clut = image_clut32;
58 | tex8.ClutPSM = GS_PSM_CT32;
59 | tex8.VramClut = gsKit_vram_alloc(gsGlobal, gsKit_texture_size(16, 16, GS_PSM_CT32), GSKIT_ALLOC_USERBUFFER);
60 | tex8.Filter = GS_FILTER_LINEAR;
61 | gsKit_texture_upload(gsGlobal, &tex8);
62 |
63 | gsKit_clear(gsGlobal, Black);
64 | gsKit_clear(gsGlobal, White);
65 | gsKit_prim_sprite_texture(gsGlobal, &tex, 0, 0, 0, 0, 256, 256, 256, 256, 0, 0x80808080);
66 | gsKit_prim_sprite_texture(gsGlobal, &tex8, 256, 0, 0, 0, 512, 256, 256, 256, 0, 0x80808080);
67 |
68 | while(1)
69 | {
70 | gsKit_sync_flip(gsGlobal);
71 | gsKit_queue_exec(gsGlobal);
72 | }
73 |
74 | return 0;
75 | }
76 |
77 |
--------------------------------------------------------------------------------
/examples/modetest/modetest.c:
--------------------------------------------------------------------------------
1 | /*
2 | * How to use:
3 | * L1/R1: Cycle through all video modes
4 | * R3: Change X/Y offset of screen
5 | * X: Switch between FIELD and FRAME mode
6 | * LEFT/RIGHT: Change width in units of 64 pixels
7 | * UP/DOWN: Change height in units of 2 pixels
8 | *
9 | * Use ps2client to see the debug output, for example:
10 | * Mode: 480i 576x452 GS_FIELD offset: -6, 0 memory: 576KiB
11 | */
12 |
13 | #include
14 |
15 | #include
16 | #include
17 |
18 | #include "libpad.h"
19 |
20 | extern int port, slot;
21 | extern int pad_init();
22 | u32 old_pad = 0;
23 |
24 | struct SMode {
25 | const char * sMode;
26 | s16 Mode;
27 | s16 Interlace;
28 | s16 Field;
29 | int MaxWidth;
30 | int MaxHeight;
31 | int Width;
32 | int Height;
33 | int VCK;
34 | int XOff;
35 | int YOff;
36 | };
37 |
38 | struct SMode modes[] = {
39 | // NTSC
40 | { "480i", GS_MODE_NTSC, GS_INTERLACED, GS_FIELD, 704, 480, 704, 452, 4, 0, 0},
41 | { "480p", GS_MODE_DTV_480P, GS_NONINTERLACED, GS_FRAME, 704, 480, 704, 452, 2, 0, 0},
42 | // PAL
43 | { "576i", GS_MODE_PAL, GS_INTERLACED, GS_FIELD, 704, 576, 704, 536, 4, 0, 0},
44 | { "576p", GS_MODE_DTV_576P, GS_NONINTERLACED, GS_FRAME, 704, 576, 704, 536, 2, 0, 0},
45 | // HDTV
46 | { "720p", GS_MODE_DTV_720P, GS_NONINTERLACED, GS_FRAME, 1280, 720, 1280, 698, 1, 0, 0},
47 | {"1080i", GS_MODE_DTV_1080I, GS_INTERLACED, GS_FIELD, 1920, 1080, 1920, 1080, 1, 0, 0},
48 | };
49 | int iCurrentMode = 0;
50 | struct SMode * pCurrentMode = &modes[0];
51 | int iModeChange = 1;
52 |
53 | void
54 | print_mode(GSGLOBAL *gsGlobal)
55 | {
56 | printf("Mode: %s %dx%d %s offset: %d, %d memory: %dKiB\n",
57 | pCurrentMode->sMode,
58 | gsGlobal->Width,
59 | gsGlobal->Height,
60 | pCurrentMode->Field == GS_FRAME ? "GS_FRAME" : "GS_FIELD",
61 | pCurrentMode->XOff,
62 | pCurrentMode->YOff,
63 | gsGlobal->CurrentPointer / 1024);
64 | }
65 |
66 | void
67 | render(GSGLOBAL *gsGlobal)
68 | {
69 | const float fBorder1 = 4.0f;
70 | const float fBorder2 = 16.0f;
71 | const u64 clBorder1 = GS_SETREG_RGBAQ(255,0,0,0,0); // Red
72 | const u64 clBorder2 = GS_SETREG_RGBAQ(255,255,255,0,0); // White
73 | const u64 clBackground = GS_SETREG_RGBAQ(64,128,255,0,0); // Light blue
74 | float fYFactor = 1.0f;
75 |
76 | gsKit_queue_reset(gsGlobal->Per_Queue);
77 |
78 | gsKit_mode_switch(gsGlobal, GS_PERSISTENT);
79 | gsKit_clear(gsGlobal, clBorder1);
80 |
81 | if ((pCurrentMode->Interlace == GS_INTERLACED) && (pCurrentMode->Field == GS_FRAME))
82 | fYFactor = 0.5f;
83 |
84 | gsKit_prim_quad(gsGlobal, fBorder1, fBorder1*fYFactor,
85 | fBorder1, gsGlobal->Height-fBorder1*fYFactor,
86 | gsGlobal->Width-fBorder1, fBorder1*fYFactor,
87 | gsGlobal->Width-fBorder1, gsGlobal->Height-fBorder1*fYFactor,
88 | 1, clBorder2);
89 |
90 | gsKit_prim_quad(gsGlobal, fBorder2, fBorder2*fYFactor,
91 | fBorder2, gsGlobal->Height-fBorder2*fYFactor,
92 | gsGlobal->Width-fBorder2, fBorder2*fYFactor,
93 | gsGlobal->Width-fBorder2, gsGlobal->Height-fBorder2*fYFactor,
94 | 1, clBackground);
95 |
96 | gsKit_queue_exec(gsGlobal);
97 | }
98 |
99 | void
100 | get_pad(GSGLOBAL *gsGlobal)
101 | {
102 | struct padButtonStatus buttons;
103 | u32 paddata;
104 | u32 new_pad;
105 | int ret;
106 |
107 | do {
108 | ret=padGetState(port, slot);
109 | } while((ret != PAD_STATE_STABLE) && (ret != PAD_STATE_FINDCTP1));
110 |
111 | ret = padRead(port, slot, &buttons);
112 |
113 | if (ret != 0) {
114 | float fXOff;
115 | float fYOff;
116 |
117 | paddata = 0xffff ^ buttons.btns;
118 |
119 | new_pad = paddata & ~old_pad;
120 | old_pad = paddata;
121 |
122 | fXOff = (buttons.rjoy_h - 128.0f) / 128.0f;
123 | if ((fXOff < -0.5f) || (fXOff > 0.5f)) {
124 | static float fXOffAccum = 0.0f;
125 | //printf("%f\n", fXOff);
126 | fXOffAccum += fXOff/5.0f;
127 | if ((fXOffAccum < -1.0f) || (fXOffAccum > 1.0f)) {
128 | int iOff = fXOffAccum;
129 | pCurrentMode->XOff += iOff;
130 | fXOffAccum -= iOff;
131 | gsKit_set_display_offset(gsGlobal, pCurrentMode->XOff * pCurrentMode->VCK, pCurrentMode->YOff);
132 | print_mode(gsGlobal);
133 | }
134 | }
135 |
136 | fYOff = (buttons.rjoy_v - 128.0f) / 128.0f;
137 | if ((fYOff < -0.5f) || (fYOff > 0.5f)) {
138 | static float fYOffAccum = 0.0f;
139 | //printf("%f\n", fYOff);
140 | fYOffAccum += fYOff/5.0f;
141 | if ((fYOffAccum < -1.0f) || (fYOffAccum > 1.0f)) {
142 | int iOff = fYOffAccum;
143 | pCurrentMode->YOff += iOff;
144 | fYOffAccum -= iOff;
145 | gsKit_set_display_offset(gsGlobal, pCurrentMode->XOff * pCurrentMode->VCK, pCurrentMode->YOff);
146 | print_mode(gsGlobal);
147 | }
148 | }
149 |
150 | // Change width
151 | if(new_pad & PAD_LEFT) {
152 | if (pCurrentMode->Width > 64) {
153 | pCurrentMode->Width -= 64;
154 | iModeChange = 1;
155 | }
156 | }
157 | if(new_pad & PAD_RIGHT) {
158 | if (pCurrentMode->Width < pCurrentMode->MaxWidth) {
159 | pCurrentMode->Width += 64;
160 | iModeChange = 1;
161 | }
162 | }
163 |
164 | // Change height
165 | if(new_pad & PAD_DOWN) {
166 | if (pCurrentMode->Height > 64) {
167 | pCurrentMode->Height -= 2;
168 | iModeChange = 1;
169 | }
170 | }
171 | if(new_pad & PAD_UP) {
172 | if (pCurrentMode->Height < pCurrentMode->MaxHeight) {
173 | pCurrentMode->Height += 2;
174 | iModeChange = 1;
175 | }
176 | }
177 |
178 | // Switch between FIELD and FRAME mode
179 | if(new_pad & PAD_CROSS) {
180 | if (pCurrentMode->Interlace == GS_INTERLACED) {
181 | pCurrentMode->Field = (pCurrentMode->Field == GS_FRAME) ? GS_FIELD : GS_FRAME;
182 | iModeChange = 1;
183 | }
184 | }
185 |
186 | // Change mode
187 | if(new_pad & PAD_R1) {
188 | iCurrentMode++;
189 | if (iCurrentMode > 5)
190 | iCurrentMode = 0;
191 | iModeChange = 1;
192 | }
193 | if(new_pad & PAD_L1) {
194 | iCurrentMode--;
195 | if (iCurrentMode < 0)
196 | iCurrentMode = 5;
197 | iModeChange = 1;
198 | }
199 | }
200 | }
201 |
202 | int main(int argc, char *argv[])
203 | {
204 | GSGLOBAL *gsGlobal = gsKit_init_global();
205 |
206 | printf("\n");
207 | printf("--------------------------------------------------------------------------------\n");
208 | printf("------------------------------- !!! WARNING !!! --------------------------------\n");
209 | printf("--------------------------------------------------------------------------------\n");
210 | printf("- -\n");
211 | printf("- This example uses 'HIRES': -\n");
212 | printf("- -\n");
213 | printf("- HIRES saves VRAM by having only the part of the frame -\n");
214 | printf("- in VRAM that is currently being read by the CRTC. -\n");
215 | printf("- -\n");
216 | printf("- Use it on a REAL PS2! -\n");
217 | printf("- On an emulator (PCSX2), you will only see part of the screen. -\n");
218 | printf("- -\n");
219 | printf("--------------------------------------------------------------------------------\n");
220 | printf("\n");
221 |
222 | pad_init();
223 |
224 | dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
225 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
226 | dmaKit_chan_init(DMA_CHANNEL_GIF);
227 |
228 | gsGlobal->DoubleBuffering = GS_SETTING_OFF;
229 | gsGlobal->ZBuffering = GS_SETTING_OFF;
230 |
231 | while(1) {
232 | if (iModeChange != 0) {
233 | iModeChange = 0;
234 | pCurrentMode = &modes[iCurrentMode];
235 |
236 | gsGlobal->PSM = GS_PSM_CT16;
237 | gsGlobal->PSMZ = GS_PSMZ_16;
238 | gsGlobal->Mode = pCurrentMode->Mode;
239 | gsGlobal->Interlace = pCurrentMode->Interlace;
240 | gsGlobal->Field = pCurrentMode->Field;
241 | gsGlobal->Width = pCurrentMode->Width;
242 | if ((pCurrentMode->Interlace == GS_INTERLACED) && (pCurrentMode->Field == GS_FRAME))
243 | gsGlobal->Height = pCurrentMode->Height/2;
244 | else
245 | gsGlobal->Height = pCurrentMode->Height;
246 |
247 | gsKit_vram_clear(gsGlobal);
248 | gsKit_init_screen(gsGlobal);
249 | gsKit_set_display_offset(gsGlobal, pCurrentMode->XOff * pCurrentMode->VCK, pCurrentMode->YOff);
250 |
251 | print_mode(gsGlobal);
252 |
253 | render(gsGlobal);
254 | }
255 |
256 | gsKit_sync_flip(gsGlobal);
257 | get_pad(gsGlobal);
258 | }
259 |
260 | return 0;
261 | }
262 |
--------------------------------------------------------------------------------
/examples/modetest/pad.c:
--------------------------------------------------------------------------------
1 | /*
2 | # _____ ___ ____ ___ ____
3 | # ____| | ____| | | |____|
4 | # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 | #-----------------------------------------------------------------------
6 | # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 | # Licenced under Academic Free License version 2.0
8 | # Review ps2sdk README & LICENSE files for further details.
9 | #
10 | # $Id$
11 | # Pad demo app
12 | # Quick and dirty, little or no error checks etc..
13 | # Distributed as is
14 | */
15 |
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 |
22 | #include "libpad.h"
23 |
24 | /*
25 | * Global var's
26 | */
27 | // pad_dma_buf is provided by the user, one buf for each pad
28 | // contains the pad's current state
29 | static char padBuf[256] __attribute__((aligned(64)));
30 |
31 | static char actAlign[6];
32 | static int actuators;
33 |
34 | int port, slot;
35 |
36 | /*
37 | * Local functions
38 | */
39 |
40 | /*
41 | * loadModules()
42 | */
43 | static void
44 | loadModules(void)
45 | {
46 | int ret;
47 |
48 |
49 | ret = SifLoadModule("rom0:SIO2MAN", 0, NULL);
50 | if (ret < 0) {
51 | printf("sifLoadModule sio failed: %d\n", ret);
52 | SleepThread();
53 | }
54 |
55 | ret = SifLoadModule("rom0:PADMAN", 0, NULL);
56 | if (ret < 0) {
57 | printf("sifLoadModule pad failed: %d\n", ret);
58 | SleepThread();
59 | }
60 | }
61 |
62 | /*
63 | * waitPadReady()
64 | */
65 | static int waitPadReady(int port, int slot)
66 | {
67 | int state;
68 | int lastState;
69 | char stateString[16];
70 |
71 | state = padGetState(port, slot);
72 | lastState = -1;
73 | while((state != PAD_STATE_STABLE) && (state != PAD_STATE_FINDCTP1)) {
74 | if (state != lastState) {
75 | padStateInt2String(state, stateString);
76 | printf("Please wait, pad(%d,%d) is in state %s\n",
77 | port, slot, stateString);
78 | }
79 | lastState = state;
80 | state=padGetState(port, slot);
81 | }
82 | // Were the pad ever 'out of sync'?
83 | if (lastState != -1) {
84 | printf("Pad OK!\n");
85 | }
86 | return 0;
87 | }
88 |
89 |
90 | /*
91 | * initializePad()
92 | */
93 | static int
94 | initializePad(int port, int slot)
95 | {
96 |
97 | int ret;
98 | int modes;
99 | int i;
100 |
101 | waitPadReady(port, slot);
102 |
103 | // How many different modes can this device operate in?
104 | // i.e. get # entrys in the modetable
105 | modes = padInfoMode(port, slot, PAD_MODETABLE, -1);
106 | printf("The device has %d modes\n", modes);
107 |
108 | if (modes > 0) {
109 | printf("( ");
110 | for (i = 0; i < modes; i++) {
111 | printf("%d ", padInfoMode(port, slot, PAD_MODETABLE, i));
112 | }
113 | printf(")");
114 | }
115 |
116 | printf("It is currently using mode %d\n",
117 | padInfoMode(port, slot, PAD_MODECURID, 0));
118 |
119 | // If modes == 0, this is not a Dual shock controller
120 | // (it has no actuator engines)
121 | if (modes == 0) {
122 | printf("This is a digital controller?\n");
123 | return 1;
124 | }
125 |
126 | // Verify that the controller has a DUAL SHOCK mode
127 | i = 0;
128 | do {
129 | if (padInfoMode(port, slot, PAD_MODETABLE, i) == PAD_TYPE_DUALSHOCK)
130 | break;
131 | i++;
132 | } while (i < modes);
133 | if (i >= modes) {
134 | printf("This is no Dual Shock controller\n");
135 | return 1;
136 | }
137 |
138 | // If ExId != 0x0 => This controller has actuator engines
139 | // This check should always pass if the Dual Shock test above passed
140 | ret = padInfoMode(port, slot, PAD_MODECUREXID, 0);
141 | if (ret == 0) {
142 | printf("This is no Dual Shock controller??\n");
143 | return 1;
144 | }
145 |
146 | printf("Enabling dual shock functions\n");
147 |
148 | // When using MMODE_LOCK, user cant change mode with Select button
149 | padSetMainMode(port, slot, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK);
150 |
151 | waitPadReady(port, slot);
152 | printf("infoPressMode: %d\n", padInfoPressMode(port, slot));
153 |
154 | waitPadReady(port, slot);
155 | printf("enterPressMode: %d\n", padEnterPressMode(port, slot));
156 |
157 | waitPadReady(port, slot);
158 | actuators = padInfoAct(port, slot, -1, 0);
159 | printf("# of actuators: %d\n",actuators);
160 |
161 | if (actuators != 0) {
162 | actAlign[0] = 0; // Enable small engine
163 | actAlign[1] = 1; // Enable big engine
164 | actAlign[2] = 0xff;
165 | actAlign[3] = 0xff;
166 | actAlign[4] = 0xff;
167 | actAlign[5] = 0xff;
168 |
169 | waitPadReady(port, slot);
170 | printf("padSetActAlign: %d\n",
171 | padSetActAlign(port, slot, actAlign));
172 | }
173 | else {
174 | printf("Did not find any actuators.\n");
175 | }
176 |
177 | waitPadReady(port, slot);
178 |
179 | return 1;
180 | }
181 |
182 | void
183 | pad_init()
184 | {
185 | int ret;
186 |
187 | SifInitRpc(0);
188 |
189 | loadModules();
190 |
191 | padInit(0);
192 |
193 | port = 0; // 0 -> Connector 1, 1 -> Connector 2
194 | slot = 0; // Always zero if not using multitap
195 |
196 | printf("PortMax: %d\n", padGetPortMax());
197 | printf("SlotMax: %d\n", padGetSlotMax(port));
198 |
199 |
200 | if((ret = padPortOpen(port, slot, padBuf)) == 0) {
201 | printf("padOpenPort failed: %d\n", ret);
202 | SleepThread();
203 | }
204 |
205 | if(!initializePad(port, slot)) {
206 | printf("pad initalization failed!\n");
207 | SleepThread();
208 | }
209 | }
210 |
--------------------------------------------------------------------------------
/examples/modetesthires/modetesthires.c:
--------------------------------------------------------------------------------
1 | /*
2 | * How to use:
3 | * L1/R1: Cycle through all video modes
4 | *
5 | * Use ps2client to see the debug output, for example:
6 | * Mode: 720p 1280x720 GS_Frame offset: 0, 0 memory: 576KiB
7 | */
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include "libpad.h"
15 |
16 | extern int port, slot;
17 | extern int pad_init();
18 | u32 old_pad = 0;
19 |
20 | struct SMode {
21 | const char * sMode;
22 | s16 Mode;
23 | s16 Interlace;
24 | s16 Field;
25 | int MaxWidth;
26 | int MaxHeight;
27 | int Width;
28 | int Height;
29 | int VCK;
30 | int XOff;
31 | int YOff;
32 | int iPassCount;
33 | };
34 |
35 | struct SMode modes[] = {
36 | { "720p", GS_MODE_DTV_720P, GS_NONINTERLACED, GS_FRAME, 1280, 720, 1280, 720, 0, 0, 0, 3},
37 | {"1080i", GS_MODE_DTV_1080I, GS_INTERLACED, GS_FRAME, 1920, 1080, 1920, 1080, 0, 0, 0, 3},
38 | };
39 | int iCurrentMode = 0;
40 | struct SMode * pCurrentMode = &modes[0];
41 | int iModeChange = 1;
42 |
43 | #define TEXTURE_WIDTH (320)
44 | #define TEXTURE_HEIGHT (240)
45 |
46 | unsigned int __attribute__((aligned(16))) tex256[TEXTURE_WIDTH*TEXTURE_HEIGHT];
47 |
48 | static void prepareTexture(void) {
49 | // initialize texture
50 | unsigned int i,j;
51 |
52 | for (j = 0; j < TEXTURE_HEIGHT; ++j)
53 | {
54 | for (i = 0; i < TEXTURE_WIDTH; ++i)
55 | {
56 | tex256[i + j * TEXTURE_WIDTH] = j * i;
57 | }
58 | }
59 | }
60 |
61 | static void set_texture(GSTEXTURE *texture, const void *frame,
62 | int width, int height, int PSM, int filter)
63 | {
64 | texture->Width = width;
65 | texture->Height = height;
66 | texture->PSM = PSM;
67 | texture->Filter = filter;
68 | texture->Mem = (void *)frame;
69 | }
70 |
71 | static void print_mode(GSGLOBAL *gsGlobal)
72 | {
73 | printf("Mode: %s %dx%d %s offset: %d, %d memory: %dKiB\n",
74 | pCurrentMode->sMode,
75 | gsGlobal->Width,
76 | gsGlobal->Height,
77 | pCurrentMode->Field == GS_FRAME ? "GS_FRAME" : "GS_FIELD",
78 | pCurrentMode->XOff,
79 | pCurrentMode->YOff,
80 | gsGlobal->CurrentPointer / 1024);
81 | }
82 |
83 | static void get_pad(GSGLOBAL *gsGlobal)
84 | {
85 | struct padButtonStatus buttons;
86 | u32 paddata;
87 | u32 new_pad;
88 | int ret;
89 |
90 | do {
91 | ret=padGetState(port, slot);
92 | } while((ret != PAD_STATE_STABLE) && (ret != PAD_STATE_FINDCTP1));
93 |
94 | ret = padRead(port, slot, &buttons);
95 |
96 | if (ret != 0) {
97 | paddata = 0xffff ^ buttons.btns;
98 |
99 | new_pad = paddata & ~old_pad;
100 | old_pad = paddata;
101 |
102 | // Change mode
103 | if(new_pad & PAD_R1) {
104 | iCurrentMode++;
105 | if (iCurrentMode > 1)
106 | iCurrentMode = 0;
107 | iModeChange = 1;
108 | }
109 | if(new_pad & PAD_L1) {
110 | iCurrentMode--;
111 | if (iCurrentMode < 0)
112 | iCurrentMode = 1;
113 | iModeChange = 1;
114 | }
115 | }
116 | }
117 |
118 | int main(int argc, char *argv[])
119 | {
120 | u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
121 | GSGLOBAL *gsGlobal = NULL;
122 | GSTEXTURE *texture = calloc(1, sizeof(*texture));
123 |
124 | printf("\n");
125 | printf("--------------------------------------------------------------------------------\n");
126 | printf("------------------------------- !!! WARNING !!! --------------------------------\n");
127 | printf("--------------------------------------------------------------------------------\n");
128 | printf("- -\n");
129 | printf("- This example uses 'HIRES': -\n");
130 | printf("- -\n");
131 | printf("- HIRES saves VRAM by having only the part of the frame -\n");
132 | printf("- in VRAM that is currently being read by the CRTC. -\n");
133 | printf("- -\n");
134 | printf("- Use it on a REAL PS2! -\n");
135 | printf("- On an emulator (PCSX2), you will only see part of the screen. -\n");
136 | printf("- -\n");
137 | printf("--------------------------------------------------------------------------------\n");
138 | printf("\n");
139 |
140 | pad_init();
141 |
142 | // Load textures
143 | prepareTexture();
144 | set_texture(texture, tex256, TEXTURE_WIDTH, TEXTURE_HEIGHT, GS_PSM_CT32, GS_FILTER_LINEAR);
145 |
146 | dmaKit_init(D_CTRL_RELE_OFF, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
147 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
148 |
149 | // Initialize the DMAC
150 | dmaKit_chan_init(DMA_CHANNEL_GIF);
151 |
152 | while(1) {
153 | if (iModeChange != 0) {
154 | iModeChange = 0;
155 | pCurrentMode = &modes[iCurrentMode];
156 |
157 | if(gsGlobal!= NULL) {
158 | gsKit_hires_deinit_global(gsGlobal);
159 | }
160 | gsGlobal = gsKit_hires_init_global();
161 |
162 | gsGlobal->PSM = GS_PSM_CT16S;
163 | gsGlobal->PSMZ = GS_PSMZ_16S;
164 | gsGlobal->Mode = pCurrentMode->Mode;
165 | gsGlobal->Interlace = pCurrentMode->Interlace;
166 | gsGlobal->Field = pCurrentMode->Field;
167 | gsGlobal->Width = pCurrentMode->Width;
168 | gsGlobal->Dithering = GS_SETTING_ON;
169 | gsGlobal->DoubleBuffering = GS_SETTING_ON;
170 | gsGlobal->ZBuffering = GS_SETTING_ON;
171 | if ((pCurrentMode->Interlace == GS_INTERLACED) && (pCurrentMode->Field == GS_FRAME))
172 | gsGlobal->Height = pCurrentMode->Height/2;
173 | else
174 | gsGlobal->Height = pCurrentMode->Height;
175 |
176 | gsKit_hires_init_screen(gsGlobal, pCurrentMode->iPassCount);
177 | gsKit_set_display_offset(gsGlobal, pCurrentMode->XOff * pCurrentMode->VCK, pCurrentMode->YOff);
178 |
179 | print_mode(gsGlobal);
180 |
181 | printf("VRAM used: %dKiB\n", gsGlobal->CurrentPointer / 1024);
182 | printf("VRAM free: %dKiB\n", 4096 - (gsGlobal->CurrentPointer / 1024));
183 | }
184 |
185 | gsKit_TexManager_bind(gsGlobal, texture);
186 |
187 | gsKit_prim_sprite_texture(gsGlobal, texture,
188 | 0, //X1
189 | 0, // Y1
190 | 0, // U1
191 | 0, // V1
192 | gsGlobal->Width, // X2
193 | gsGlobal->Height, // Y2
194 | texture->Width, // U2
195 | texture->Height, // V2
196 | 0,
197 | TexCol);
198 |
199 | gsKit_hires_sync(gsGlobal);
200 | gsKit_hires_flip(gsGlobal);
201 | gsKit_TexManager_nextFrame(gsGlobal);
202 | get_pad(gsGlobal);
203 | }
204 |
205 | gsKit_hires_deinit_global(gsGlobal);
206 |
207 | return 0;
208 | }
209 |
--------------------------------------------------------------------------------
/examples/modetesthires/pad.c:
--------------------------------------------------------------------------------
1 | /*
2 | # _____ ___ ____ ___ ____
3 | # ____| | ____| | | |____|
4 | # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 | #-----------------------------------------------------------------------
6 | # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 | # Licenced under Academic Free License version 2.0
8 | # Review ps2sdk README & LICENSE files for further details.
9 | #
10 | # $Id$
11 | # Pad demo app
12 | # Quick and dirty, little or no error checks etc..
13 | # Distributed as is
14 | */
15 |
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 |
22 | #include "libpad.h"
23 |
24 | /*
25 | * Global var's
26 | */
27 | // pad_dma_buf is provided by the user, one buf for each pad
28 | // contains the pad's current state
29 | static char padBuf[256] __attribute__((aligned(64)));
30 |
31 | static char actAlign[6];
32 | static int actuators;
33 |
34 | int port, slot;
35 |
36 | /*
37 | * Local functions
38 | */
39 |
40 | /*
41 | * loadModules()
42 | */
43 | static void
44 | loadModules(void)
45 | {
46 | int ret;
47 |
48 |
49 | ret = SifLoadModule("rom0:SIO2MAN", 0, NULL);
50 | if (ret < 0) {
51 | printf("sifLoadModule sio failed: %d\n", ret);
52 | SleepThread();
53 | }
54 |
55 | ret = SifLoadModule("rom0:PADMAN", 0, NULL);
56 | if (ret < 0) {
57 | printf("sifLoadModule pad failed: %d\n", ret);
58 | SleepThread();
59 | }
60 | }
61 |
62 | /*
63 | * waitPadReady()
64 | */
65 | static int waitPadReady(int port, int slot)
66 | {
67 | int state;
68 | int lastState;
69 | char stateString[16];
70 |
71 | state = padGetState(port, slot);
72 | lastState = -1;
73 | while((state != PAD_STATE_STABLE) && (state != PAD_STATE_FINDCTP1)) {
74 | if (state != lastState) {
75 | padStateInt2String(state, stateString);
76 | printf("Please wait, pad(%d,%d) is in state %s\n",
77 | port, slot, stateString);
78 | }
79 | lastState = state;
80 | state=padGetState(port, slot);
81 | }
82 | // Were the pad ever 'out of sync'?
83 | if (lastState != -1) {
84 | printf("Pad OK!\n");
85 | }
86 | return 0;
87 | }
88 |
89 |
90 | /*
91 | * initializePad()
92 | */
93 | static int
94 | initializePad(int port, int slot)
95 | {
96 |
97 | int ret;
98 | int modes;
99 | int i;
100 |
101 | waitPadReady(port, slot);
102 |
103 | // How many different modes can this device operate in?
104 | // i.e. get # entrys in the modetable
105 | modes = padInfoMode(port, slot, PAD_MODETABLE, -1);
106 | printf("The device has %d modes\n", modes);
107 |
108 | if (modes > 0) {
109 | printf("( ");
110 | for (i = 0; i < modes; i++) {
111 | printf("%d ", padInfoMode(port, slot, PAD_MODETABLE, i));
112 | }
113 | printf(")");
114 | }
115 |
116 | printf("It is currently using mode %d\n",
117 | padInfoMode(port, slot, PAD_MODECURID, 0));
118 |
119 | // If modes == 0, this is not a Dual shock controller
120 | // (it has no actuator engines)
121 | if (modes == 0) {
122 | printf("This is a digital controller?\n");
123 | return 1;
124 | }
125 |
126 | // Verify that the controller has a DUAL SHOCK mode
127 | i = 0;
128 | do {
129 | if (padInfoMode(port, slot, PAD_MODETABLE, i) == PAD_TYPE_DUALSHOCK)
130 | break;
131 | i++;
132 | } while (i < modes);
133 | if (i >= modes) {
134 | printf("This is no Dual Shock controller\n");
135 | return 1;
136 | }
137 |
138 | // If ExId != 0x0 => This controller has actuator engines
139 | // This check should always pass if the Dual Shock test above passed
140 | ret = padInfoMode(port, slot, PAD_MODECUREXID, 0);
141 | if (ret == 0) {
142 | printf("This is no Dual Shock controller??\n");
143 | return 1;
144 | }
145 |
146 | printf("Enabling dual shock functions\n");
147 |
148 | // When using MMODE_LOCK, user cant change mode with Select button
149 | padSetMainMode(port, slot, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK);
150 |
151 | waitPadReady(port, slot);
152 | printf("infoPressMode: %d\n", padInfoPressMode(port, slot));
153 |
154 | waitPadReady(port, slot);
155 | printf("enterPressMode: %d\n", padEnterPressMode(port, slot));
156 |
157 | waitPadReady(port, slot);
158 | actuators = padInfoAct(port, slot, -1, 0);
159 | printf("# of actuators: %d\n",actuators);
160 |
161 | if (actuators != 0) {
162 | actAlign[0] = 0; // Enable small engine
163 | actAlign[1] = 1; // Enable big engine
164 | actAlign[2] = 0xff;
165 | actAlign[3] = 0xff;
166 | actAlign[4] = 0xff;
167 | actAlign[5] = 0xff;
168 |
169 | waitPadReady(port, slot);
170 | printf("padSetActAlign: %d\n",
171 | padSetActAlign(port, slot, actAlign));
172 | }
173 | else {
174 | printf("Did not find any actuators.\n");
175 | }
176 |
177 | waitPadReady(port, slot);
178 |
179 | return 1;
180 | }
181 |
182 | void
183 | pad_init()
184 | {
185 | int ret;
186 |
187 | SifInitRpc(0);
188 |
189 | loadModules();
190 |
191 | padInit(0);
192 |
193 | port = 0; // 0 -> Connector 1, 1 -> Connector 2
194 | slot = 0; // Always zero if not using multitap
195 |
196 | printf("PortMax: %d\n", padGetPortMax());
197 | printf("SlotMax: %d\n", padGetSlotMax(port));
198 |
199 |
200 | if((ret = padPortOpen(port, slot, padBuf)) == 0) {
201 | printf("padOpenPort failed: %d\n", ret);
202 | SleepThread();
203 | }
204 |
205 | if(!initializePad(port, slot)) {
206 | printf("pad initalization failed!\n");
207 | SleepThread();
208 | }
209 | }
210 |
--------------------------------------------------------------------------------
/examples/pixelperfect/128x128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/pixelperfect/128x128.png
--------------------------------------------------------------------------------
/examples/pixelperfect/132x132.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/pixelperfect/132x132.png
--------------------------------------------------------------------------------
/examples/pixelperfect/pixelperfect.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // pixelperfect.c - Example demonstrating gsKit texture operation.
10 | // Aligning the texels exactly to pixels
11 | //
12 |
13 | #include
14 | #include
15 |
16 | #include
17 | #include
18 | #include
19 |
20 |
21 | int main(int argc, char *argv[])
22 | {
23 | GSGLOBAL *gsGlobal;
24 | GSFONTM *gsFontM;
25 | GSTEXTURE tx128, tx132;
26 | char tempstr[256];
27 | int i=0;
28 | int toggle=0;
29 | float fOffsetX;
30 | float fOffsetY;
31 | float fOffsetU;
32 | float fOffsetV;
33 |
34 | u64 Black = GS_SETREG_RGBA(0x00,0x00,0x00,0x80);
35 | u64 White = GS_SETREG_RGBA(0xFF,0xFF,0xFF,0x80);
36 | u64 TexCol = GS_SETREG_RGBA(0x80,0x80,0x80,0x80);
37 |
38 | gsGlobal = gsKit_init_global();
39 | gsFontM = gsKit_init_fontm();
40 |
41 | gsGlobal->Mode = GS_MODE_DTV_480P;
42 | gsGlobal->Interlace = GS_NONINTERLACED;
43 | gsGlobal->Field = GS_FRAME;
44 | gsGlobal->Width = 704;
45 | gsGlobal->Height = 480;
46 |
47 | gsGlobal->PSM = GS_PSM_CT24;
48 | gsGlobal->PSMZ = GS_PSMZ_16S;
49 | gsGlobal->DoubleBuffering = GS_SETTING_ON;
50 | gsGlobal->ZBuffering = GS_SETTING_OFF;
51 |
52 | dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
53 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
54 |
55 | // Initialize the DMAC
56 | dmaKit_chan_init(DMA_CHANNEL_GIF);
57 |
58 | gsKit_init_screen(gsGlobal);
59 | gsKit_fontm_upload(gsGlobal, gsFontM);
60 |
61 | // Load textures
62 | tx128.Delayed = 1;
63 | tx132.Delayed = 1;
64 | gsKit_texture_png(gsGlobal, &tx128, "host:128x128.png");
65 | gsKit_texture_png(gsGlobal, &tx132, "host:132x132.png");
66 |
67 | gsKit_set_clamp(gsGlobal, GS_CMODE_CLAMP);
68 | gsKit_set_test(gsGlobal, GS_ZTEST_OFF);
69 | gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 0), 0);
70 | gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
71 |
72 | while(1) {
73 | gsKit_clear(gsGlobal, White);
74 |
75 | i++;
76 | if (i >= 60) {
77 | i=0;
78 | toggle = toggle ? 0 : 1;
79 | }
80 |
81 | if (toggle) {
82 | // Default texture mapping
83 | fOffsetX = 0.0f;
84 | fOffsetY = 0.0f;
85 | fOffsetU = 0.0f;
86 | fOffsetV = 0.0f;
87 | }
88 | else {
89 | // Pixel perfect texture mapping:
90 | // - Move to the upper-left corner of the pixel
91 | fOffsetX = -0.5f;
92 | fOffsetY = -0.5f;
93 | fOffsetU = 0.0f;
94 | fOffsetV = 0.0f;
95 | }
96 |
97 | gsKit_fontm_print_scaled(gsGlobal, gsFontM, 20, 20, 2, 0.5f, Black, "GS_FILTER_NEAREST");
98 | gsKit_fontm_print_scaled(gsGlobal, gsFontM, 20, 190, 2, 0.5f, Black, "GS_FILTER_LINEAR");
99 |
100 | tx128.Filter = GS_FILTER_NEAREST;
101 | gsKit_TexManager_bind(gsGlobal, &tx128);
102 | gsKit_prim_sprite_texture(gsGlobal, &tx128,
103 | fOffsetX+ 20.0f, // X1
104 | fOffsetY+ 40.0f, // Y2
105 | fOffsetU+ 0.0f, // U1
106 | fOffsetV+ 0.0f, // V1
107 | fOffsetX+tx128.Width + 20.0f, // X2
108 | fOffsetY+tx128.Height + 40.0f, // Y2
109 | fOffsetU+tx128.Width, // U2
110 | fOffsetV+tx128.Height, // V2
111 | 2,
112 | TexCol);
113 |
114 | tx132.Filter = GS_FILTER_NEAREST;
115 | gsKit_TexManager_bind(gsGlobal, &tx132);
116 | gsKit_prim_sprite_texture(gsGlobal, &tx132,
117 | fOffsetX+170.0f, // X1
118 | fOffsetY+ 40.0f, // Y2
119 | fOffsetU+ 2.0f, // U1
120 | fOffsetV+ 2.0f, // V1
121 | fOffsetX+tx132.Width - 4.0f + 170.0f, // X2
122 | fOffsetY+tx132.Height - 4.0f + 40.0f, // Y2
123 | fOffsetU+tx132.Width - 2.0f, // U2
124 | fOffsetV+tx132.Height - 2.0f, // V2
125 | 2,
126 | TexCol);
127 |
128 | tx128.Filter = GS_FILTER_LINEAR;
129 | gsKit_TexManager_bind(gsGlobal, &tx128);
130 | gsKit_prim_sprite_texture(gsGlobal, &tx128,
131 | fOffsetX+ 20.0f, // X1
132 | fOffsetY+210.0f, // Y2
133 | fOffsetU+ 0.0f, // U1
134 | fOffsetV+ 0.0f, // V1
135 | fOffsetX+tx128.Width + 20.0f, // X2
136 | fOffsetY+tx128.Height + 210.0f, // Y2
137 | fOffsetU+tx128.Width, // U2
138 | fOffsetV+tx128.Height, // V2
139 | 2,
140 | TexCol);
141 |
142 | tx132.Filter = GS_FILTER_LINEAR;
143 | gsKit_TexManager_bind(gsGlobal, &tx132);
144 | gsKit_prim_sprite_texture(gsGlobal, &tx132,
145 | fOffsetX+170.0f, // X1
146 | fOffsetY+210.0f, // Y2
147 | fOffsetU+ 2.0f, // U1
148 | fOffsetV+ 2.0f, // V1
149 | fOffsetX+tx132.Width - 4.0f + 170.0f, // X2
150 | fOffsetY+tx132.Height - 4.0f + 210.0f, // Y2
151 | fOffsetU+tx132.Width - 2.0f, // U2
152 | fOffsetV+tx132.Height - 2.0f, // V2
153 | 2,
154 | TexCol);
155 |
156 | // Magnified to 350x350 pixels
157 | tx132.Filter = GS_FILTER_LINEAR;
158 | gsKit_TexManager_bind(gsGlobal, &tx132);
159 | gsKit_prim_sprite_texture(gsGlobal, &tx132,
160 | fOffsetX+320.0f, // X1
161 | fOffsetY+ 40.0f, // Y2
162 | fOffsetU+ 2.0f, // U1
163 | fOffsetV+ 2.0f, // V1
164 | fOffsetX+350.0f + 320.0f, // X2
165 | fOffsetY+350.0f + 40.0f, // Y2
166 | fOffsetU+tx132.Width - 2.0f, // U2
167 | fOffsetV+tx132.Height - 2.0f, // V2
168 | 2,
169 | TexCol);
170 |
171 | sprintf(tempstr, "fOffsetXY = %.3f %.3f", fOffsetX, fOffsetY);
172 | gsKit_fontm_print_scaled(gsGlobal, gsFontM, 20, 400, 2, 0.5f, Black, tempstr);
173 | sprintf(tempstr, "fOffsetUV = %.3f %.3f", fOffsetU, fOffsetV);
174 | gsKit_fontm_print_scaled(gsGlobal, gsFontM, 20, 430, 2, 0.5f, Black, tempstr);
175 |
176 | gsKit_queue_exec(gsGlobal);
177 | gsKit_sync_flip(gsGlobal);
178 | gsKit_TexManager_nextFrame(gsGlobal);
179 | }
180 |
181 | return 0;
182 | }
183 |
--------------------------------------------------------------------------------
/examples/png-texture/test.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/png-texture/test.png
--------------------------------------------------------------------------------
/examples/png-texture/textures.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // textures.c - Example demonstrating gsKit texture operation.
10 | //
11 |
12 | #include
13 | #include
14 |
15 | #include
16 | #include
17 | #include
18 |
19 | int main(int argc, char *argv[])
20 | {
21 | GSGLOBAL *gsGlobal;
22 |
23 | GSTEXTURE Tex1;
24 | int x = 0, y = 0;
25 |
26 | #ifdef HAVE_LIBPNG
27 | u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
28 | #endif
29 | u64 White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
30 | u64 BlueTrans = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x40,0x00);
31 | u64 Green = GS_SETREG_RGBAQ(0x00,0xFF,0x00,0x00,0x00);
32 |
33 | float VHeight;
34 |
35 | gsGlobal = gsKit_init_global();
36 |
37 | Tex1.Width = 0;
38 | Tex1.Height = 0;
39 |
40 | gsGlobal->PSM = GS_PSM_CT32;
41 | gsGlobal->PSMZ = GS_PSMZ_16S;
42 | gsGlobal->ZBuffering = GS_SETTING_ON;
43 |
44 | dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
45 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
46 |
47 | // Initialize the DMAC
48 | dmaKit_chan_init(DMA_CHANNEL_GIF);
49 | #ifdef HAVE_LIBPNG
50 | printf("alpha\n");
51 | gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
52 | #endif
53 | gsKit_init_screen(gsGlobal);
54 |
55 | VHeight = gsGlobal->Height;
56 |
57 | gsKit_clear(gsGlobal, White);
58 | #ifdef HAVE_LIBPNG
59 | gsKit_texture_png(gsGlobal, &Tex1, "host:test.png");
60 | printf("Texture 1 Height: %i\n",Tex1.Height);
61 | printf("Texture 1 Width: %i\n",Tex1.Width);
62 |
63 | printf("Texure 1 VRAM Range = 0x%X - 0x%X\n",Tex1.Vram, Tex1.Vram +gsKit_texture_size(Tex1.Width, Tex1.Height, Tex1.PSM) - 1);
64 | #endif
65 | gsKit_mode_switch(gsGlobal, GS_PERSISTENT);
66 |
67 | while(1)
68 | {
69 |
70 | if( y <= 10 && (x + Tex1.Width) < (gsGlobal->Width - 10))
71 | x+=10;
72 | else if( (y + Tex1.Height) < (VHeight - 10) && (x + Tex1.Width) >= (gsGlobal->Width - 10) )
73 | y+=10;
74 | else if( (y + Tex1.Height) >= (VHeight - 10) && x > 10 )
75 | x-=10;
76 | else if( y > 10 && x <= 10 )
77 | y-=10;
78 |
79 | gsKit_clear(gsGlobal, Green);
80 |
81 | gsKit_prim_sprite(gsGlobal, x, y, x + Tex1.Width, y + Tex1.Height, 1, BlueTrans);
82 | #ifdef HAVE_LIBPNG
83 | gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0,1,0,1,0), 0);
84 | gsKit_set_test(gsGlobal, GS_ATEST_OFF);
85 |
86 | gsKit_prim_sprite_texture(gsGlobal, &Tex1, 0.0f, // X1
87 | 0.0f, // Y2
88 | 0.0f, // U1
89 | 0.0f, // V1
90 | Tex1.Width, // X2
91 | Tex1.Height, // Y2
92 | Tex1.Width, // U2
93 | Tex1.Height, // V2
94 | 2,
95 | TexCol);
96 |
97 |
98 | gsKit_set_test(gsGlobal, GS_ATEST_ON);
99 | gsKit_set_primalpha(gsGlobal, GS_BLEND_BACK2FRONT, 0);
100 | #endif
101 | gsKit_sync_flip(gsGlobal);
102 | gsKit_queue_exec(gsGlobal);
103 | #ifdef HAVE_LIBPNG
104 | gsKit_queue_reset(gsGlobal->Per_Queue);
105 | #endif
106 | }
107 |
108 | return 0;
109 | }
110 |
--------------------------------------------------------------------------------
/examples/texstream/texstream.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // texstream.c - Example demonstrating gsKit texture streaming operation.
10 | //
11 |
12 | #include
13 | #include
14 |
15 | #include
16 | #include
17 | #include
18 |
19 | int main(int argc, char *argv[])
20 | {
21 | GSGLOBAL *gsGlobal;
22 | //GS_MODE_VGA_640_60
23 | #ifdef HAVE_LIBPNG
24 | GSTEXTURE Sprite;
25 | #endif
26 | u64 White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
27 | #ifdef HAVE_LIBPNG
28 | u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
29 | #endif
30 |
31 | gsGlobal = gsKit_init_global();
32 |
33 | #ifdef HAVE_LIBPNG
34 | Sprite.Width = 0;
35 | Sprite.Height = 0;
36 | Sprite.PSM = 0;
37 | Sprite.Mem = 0;
38 | Sprite.TBW = 0;
39 | #endif
40 | gsGlobal->PSM = GS_PSM_CT24;
41 | gsGlobal->PSMZ = GS_PSMZ_16S;
42 | // gsGlobal->DoubleBuffering = GS_SETTING_OFF;
43 | // gsGlobal->ZBuffering = GS_SETTING_OFF;
44 |
45 | dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
46 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
47 |
48 | // Initialize the DMAC
49 | dmaKit_chan_init(DMA_CHANNEL_GIF);
50 |
51 | gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
52 |
53 | gsKit_init_screen(gsGlobal);
54 |
55 | #ifdef HAVE_LIBPNG
56 | Sprite.Delayed = GS_SETTING_ON;
57 | #endif
58 |
59 | #ifdef HAVE_LIBPNG
60 | if(gsKit_texture_png(gsGlobal, &Sprite, "host:texstream.png") < 0)
61 | {
62 | printf("Loading Failed!\n");
63 | }
64 | #endif
65 |
66 | gsKit_mode_switch(gsGlobal, GS_ONESHOT);
67 |
68 | while(1)
69 | {
70 | gsKit_clear(gsGlobal, White);
71 |
72 | gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0,1,0,1,0), 0);
73 | gsKit_set_test(gsGlobal, GS_ATEST_OFF);
74 | #ifdef HAVE_LIBPNG
75 | gsKit_TexManager_bind(gsGlobal, &Sprite);
76 | gsKit_prim_sprite_texture(gsGlobal, &Sprite, 310.0f, // X1
77 | 50.0f, // Y2
78 | 0.0f, // U1
79 | 0.0f, // V1
80 | Sprite.Width + 310.0f, // X2
81 | Sprite.Height + 50.0f, // Y2
82 | Sprite.Width, // U2
83 | Sprite.Height, // V2
84 | 3,
85 | TexCol);
86 | #endif
87 | gsKit_set_test(gsGlobal, GS_ATEST_ON);
88 | gsKit_set_primalpha(gsGlobal, GS_BLEND_BACK2FRONT, 0);
89 |
90 | gsKit_sync_flip(gsGlobal);
91 |
92 | gsKit_queue_exec(gsGlobal);
93 |
94 | gsKit_TexManager_nextFrame(gsGlobal);
95 | }
96 |
97 | return 0;
98 | }
99 |
--------------------------------------------------------------------------------
/examples/texstream/texstream.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/texstream/texstream.png
--------------------------------------------------------------------------------
/examples/textures/bitmap.raw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/textures/bitmap.raw
--------------------------------------------------------------------------------
/examples/textures/bsdgirl.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/textures/bsdgirl.bmp
--------------------------------------------------------------------------------
/examples/textures/bsdgirl.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/textures/bsdgirl.jpg
--------------------------------------------------------------------------------
/examples/textures/ps2dev.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ps2dev/gsKit/2b89476e94397e16b6b10c3021aca639262ea81d/examples/textures/ps2dev.jpg
--------------------------------------------------------------------------------
/examples/textures/textures.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // textures.c - Example demonstrating gsKit texture operation.
10 | //
11 |
12 | #include
13 | #include
14 |
15 | #include
16 | #include
17 | #include
18 |
19 | int main(int argc, char *argv[])
20 | {
21 | GSGLOBAL *gsGlobal;
22 | GSTEXTURE Tex1, Tex2;
23 |
24 | #ifdef HAVE_LIBJPEG
25 | GSTEXTURE Tex3;
26 | #endif
27 |
28 | u64 White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
29 | u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
30 |
31 | gsGlobal = gsKit_init_global();
32 |
33 | gsGlobal->PSM = GS_PSM_CT24;
34 | gsGlobal->PSMZ = GS_PSMZ_16S;
35 | // gsGlobal->DoubleBuffering = GS_SETTING_OFF;
36 | // gsGlobal->ZBuffering = GS_SETTING_OFF;
37 |
38 | dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
39 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
40 |
41 | // Initialize the DMAC
42 | dmaKit_chan_init(DMA_CHANNEL_GIF);
43 |
44 | gsKit_init_screen(gsGlobal);
45 |
46 | gsKit_mode_switch(gsGlobal, GS_PERSISTENT);
47 |
48 | gsKit_clear(gsGlobal, White);
49 |
50 | Tex1.Width = 256;
51 | Tex1.Height = 256;
52 | Tex1.PSM = GS_PSM_CT24;
53 | Tex1.Filter = GS_FILTER_NEAREST;
54 |
55 | gsKit_texture_raw(gsGlobal, &Tex1, "host:bitmap.raw");
56 | printf("Texture 1 Height: %i\n",Tex1.Height);
57 | printf("Texture 1 Width: %i\n",Tex1.Width);
58 |
59 | gsKit_texture_bmp(gsGlobal, &Tex2, "host:bsdgirl.bmp");
60 | printf("Texture 2 Height: %i\n",Tex2.Height);
61 | printf("Texture 2 Width: %i\n",Tex2.Width);
62 |
63 | printf("Texure 1 VRAM Range = 0x%X - 0x%X\n",Tex1.Vram, Tex1.Vram +gsKit_texture_size(Tex1.Width, Tex1.Height, Tex1.PSM) - 1);
64 | printf("Texure 2 VRAM Range = 0x%X - 0x%X\n",Tex2.Vram, Tex2.Vram +gsKit_texture_size(Tex2.Width, Tex2.Height, Tex2.PSM) - 1);
65 |
66 | #ifdef HAVE_LIBJPEG
67 | gsKit_texture_jpeg(gsGlobal, &Tex3, "host:ps2dev.jpg");
68 |
69 | printf("Texture 3 Height: %i\n",Tex3.Height);
70 | printf("Texture 3 Width: %i\n",Tex3.Width);
71 | printf("Texure 3 VRAM Range = 0x%X - 0x%X\n",Tex3.Vram, Tex3.Vram +gsKit_texture_size(Tex3.Width, Tex3.Height, Tex3.PSM) - 1);
72 | #endif
73 |
74 | gsKit_set_clamp(gsGlobal, GS_CMODE_CLAMP);
75 |
76 | gsKit_clear(gsGlobal, White);
77 |
78 | gsKit_prim_quad_texture_3d(gsGlobal, &Tex1, 20.0f, // X1
79 | 50.0f, // Y1
80 | 1, // Z1
81 | 0.0f, // U1
82 | 0.0f, // V1
83 |
84 | 20.0f, // X2
85 | 50.0f + Tex1.Height, // Y2
86 | 1, // Z2
87 | 0.0f, // U2
88 | Tex1.Height, // V2
89 |
90 | 20.0f + Tex1.Width, // X3
91 | 50.0f, // Y3
92 | 1, // Z3
93 | Tex1.Width, // U3
94 | 0.0f, // V3
95 |
96 | Tex1.Width + 20.0f, // X4
97 | Tex1.Height + 50.0f, // Y4
98 | 1, // Z4
99 | Tex1.Width, // U4
100 | Tex1.Height, // V4
101 | TexCol);
102 |
103 | gsKit_prim_sprite_texture(gsGlobal, &Tex2, 310.0f, // X1
104 | 50.0f, // Y2
105 | 0.0f, // U1
106 | 0.0f, // V1
107 | Tex2.Width + 310.0f, // X2
108 | Tex2.Height + 50.0f, // Y2
109 | Tex2.Width, // U2
110 | Tex2.Height, // V2
111 | 2,
112 | TexCol);
113 |
114 |
115 | #ifdef HAVE_LIBJPEG
116 | gsKit_prim_sprite_texture(gsGlobal, &Tex3, 40.0f, // X1
117 | 386.0f, // Y2
118 | 0.0f, // U1
119 | 0.0f, // V1
120 | Tex3.Width + 40.0f, // X2
121 | Tex3.Height + 386.0f, // Y2
122 | Tex3.Width, // U2
123 | Tex3.Height, // V2
124 | 3,
125 | TexCol);
126 | #endif
127 |
128 | while(1)
129 | {
130 | gsKit_sync_flip(gsGlobal);
131 | gsKit_queue_exec(gsGlobal);
132 | }
133 |
134 | return 0;
135 | }
136 |
--------------------------------------------------------------------------------
/examples/vsync/vsync.c:
--------------------------------------------------------------------------------
1 | // ____ ___ | / _____ _____
2 | // | __ | |___/ | |
3 | // |___| ___| | \ __|__ | gsKit Open Source Project.
4 | // ----------------------------------------------------------------------
5 | // Copyright 2004 - Chris "Neovanglist" Gilbert
6 | // Licenced under Academic Free License version 2.0
7 | // Review gsKit README & LICENSE files for further details.
8 | //
9 | // basic.c - Example demonstrating basic gsKit operation.
10 | //
11 | #include
12 | #include
13 | #include
14 |
15 | #include
16 | #include
17 |
18 | GSGLOBAL *gsGlobal;
19 |
20 | u64 BlueTrans;
21 | u64 RedTrans;
22 | u64 GreenTrans;
23 | u64 WhiteTrans;
24 |
25 | int vsync_max = 50;
26 | float x = 10;
27 | float y = 10;
28 | float width = 150;
29 | float height = 150;
30 |
31 | float VHeight;
32 | volatile int vsync_num = 0;
33 | int frame_num = 0;
34 |
35 | static int vsync_callback(int cause)
36 | {
37 | gsKit_display_buffer(gsGlobal); // working buffer gets displayed
38 |
39 | // we only have a single buffer so we need to unlock it
40 | // after it's done displaying
41 | if (gsGlobal->DoubleBuffering == GS_SETTING_OFF)
42 | gsKit_unlock_buffer(gsGlobal);
43 |
44 | vsync_num++;
45 |
46 | ExitHandler();
47 |
48 | return 0;
49 | }
50 |
51 | static int render_frame(void)
52 | {
53 | vsync_num = 0;
54 |
55 | while(vsync_numOs_Queue); // clear the queue for the new frame
57 |
58 | if( y <= 10 && (x + width) < (gsGlobal->Width - 10))
59 | x+=10;
60 | else if( (y + height) < (VHeight - 10) && (x + width) >= (gsGlobal->Width - 10) )
61 | y+=10;
62 | else if( (y + height) >= (VHeight - 10) && x > 10 )
63 | x-=10;
64 | else if( y > 10 && x <= 10 )
65 | y-=10;
66 |
67 | // add two new sprites to queue
68 | gsKit_prim_sprite(gsGlobal, x, y, x + width, y + height, 4, BlueTrans);
69 |
70 | // RedTrans must be a oneshot for proper blending!
71 | gsKit_prim_sprite(gsGlobal, 100.0f, 100.0f, 200.0f, 200.0f, 5, RedTrans);
72 | gsKit_prim_sprite(gsGlobal, 100.0f, 200.0f, 250.0f, 250.0f, 5, GreenTrans);
73 | gsKit_prim_sprite(gsGlobal, 200.0f, 250.0f, 275.0f, 275.0f, 5, WhiteTrans);
74 |
75 | gsKit_queue_exec(gsGlobal);
76 |
77 | frame_num++;
78 |
79 | if(!(*GS_CSR & 8))
80 | continue;
81 | else {
82 | gsKit_lock_buffer(gsGlobal); // lock working buffer for displaying
83 | gsKit_vsync_nowait(); // initiate vsync which activates interrupt handler
84 |
85 | // if double buffering is enabled
86 | // unlock the old displayed buffer to be the new working buffer
87 | if (gsGlobal->DoubleBuffering == GS_SETTING_ON) {
88 | gsKit_unlock_buffer(gsGlobal);
89 | gsKit_switch_context(gsGlobal);
90 | }
91 | }
92 |
93 | // blocks until there's a buffer available
94 | // but don't block in double buffered mode
95 | //if (gsGlobal->DoubleBuffering == GS_SETTING_OFF)
96 | while(gsKit_lock_status(gsGlobal) == GS_SETTING_ON);
97 |
98 | }
99 |
100 | return 0;
101 | }
102 |
103 | int main(int argc, char *argv[])
104 | {
105 | int callback_id;
106 |
107 | u64 White, Black, Red, Green, Blue;
108 |
109 | float *LineStrip;
110 | float *LineStripPtr;
111 | float *TriStrip;
112 | float *TriStripPtr;
113 | float *TriFanPtr;
114 | float *TriFan;
115 |
116 | gsGlobal = gsKit_init_global();
117 |
118 | dmaKit_init(D_CTRL_RELE_OFF, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
119 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
120 |
121 | // Initialize the DMAC
122 | dmaKit_chan_init(DMA_CHANNEL_GIF);
123 |
124 | callback_id = gsKit_add_vsync_handler(&vsync_callback);
125 |
126 | printf("callback_id = %d\n", callback_id);
127 |
128 | // By default the gsKit_init_global() uses an autodetected interlaced field mode
129 | // To set a new mode set these five variables for the resolution desired and
130 | // mode desired
131 |
132 | // Some examples
133 | // Make sure that gsGlobal->Height is a factor of the mode's gsGlobal->DH
134 |
135 | //gsGlobal->Mode = GS_MODE_NTSC
136 | //gsGlobal->Interlace = GS_INTERLACED;
137 | //gsGlobal->Field = GS_FIELD;
138 | //gsGlobal->Width = 640;
139 | //gsGlobal->Height = 448;
140 |
141 | gsGlobal->Mode = GS_MODE_PAL;
142 | gsGlobal->Interlace = GS_INTERLACED;
143 | gsGlobal->Field = GS_FIELD;
144 | gsGlobal->Width = 640;
145 | gsGlobal->Height = 512;
146 |
147 | gsKit_init_screen(gsGlobal);
148 |
149 | //gsGlobal->Mode = GS_MODE_DTV_480P;
150 | //gsGlobal->Interlace = GS_NONINTERLACED;
151 | //gsGlobal->Field = GS_FRAME;
152 | //gsGlobal->Width = 720;
153 | //gsGlobal->Height = 480;
154 |
155 | //gsGlobal->Mode = GS_MODE_DTV_1080I;
156 | //gsGlobal->Interlace = GS_INTERLACED;
157 | //gsGlobal->Field = GS_FIELD;
158 | //gsGlobal->Width = 640;
159 | //gsGlobal->Height = 540;
160 | //gsGlobal->PSM = GS_PSM_CT16;
161 | //gsGlobal->PSMZ = GS_PSMZ_16;
162 | //gsGlobal->Dithering = GS_SETTING_ON;
163 |
164 | // A width of 640 would work as well
165 | // However a height of 720 doesn't seem to work well
166 | //gsGlobal->Mode = GS_MODE_DTV_720P;
167 | //gsGlobal->Interlace = GS_NONINTERLACED;
168 | //gsGlobal->Field = GS_FRAME;
169 | //gsGlobal->Width = 640;
170 | //gsGlobal->Height = 360;
171 | //gsGlobal->PSM = GS_PSM_CT16;
172 | //gsGlobal->PSMZ = GS_PSMZ_16;
173 |
174 | // You can use these to turn off Z/Double Buffering. They are on by default.
175 | // Modes with widths >= 1024 might not work with them on
176 | // gsGlobal->DoubleBuffering = GS_SETTING_OFF;
177 | // gsGlobal->ZBuffering = GS_SETTING_OFF;
178 |
179 | gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
180 |
181 | VHeight = gsGlobal->Height;//600;//gsGlobal->Height;
182 |
183 | LineStripPtr = LineStrip = malloc(12 * sizeof(float));
184 | *LineStrip++ = 75; // Segment 1 X
185 | *LineStrip++ = 250; // Segment 1 Y
186 | *LineStrip++ = 125; // Segment 2 X
187 | *LineStrip++ = 290; // Segment 2 Y
188 | *LineStrip++ = 100; // Segment 3 X
189 | *LineStrip++ = 350; // Segment 3 Y
190 | *LineStrip++ = 50; // Segment 4 X
191 | *LineStrip++ = 350; // Segment 4 Y
192 | *LineStrip++ = 25; // Segment 6 X
193 | *LineStrip++ = 290; // Segment 6 X
194 | *LineStrip++ = 75; // Segment 6 Y
195 | *LineStrip++ = 250; // Segment 6 Y
196 |
197 | TriStripPtr = TriStrip = malloc(12 * sizeof(float));
198 | *TriStrip++ = 550;
199 | *TriStrip++ = 100;
200 | *TriStrip++ = 525;
201 | *TriStrip++ = 125;
202 | *TriStrip++ = 575;
203 | *TriStrip++ = 125;
204 | *TriStrip++ = 550;
205 | *TriStrip++ = 150;
206 | *TriStrip++ = 600;
207 | *TriStrip++ = 150;
208 | *TriStrip++ = 575;
209 | *TriStrip++ = 175;
210 |
211 | TriFanPtr = TriFan = malloc(16 * sizeof(float));
212 | *TriFan++ = 300;
213 | *TriFan++ = 100;
214 | *TriFan++ = 225;
215 | *TriFan++ = 100;
216 | *TriFan++ = 235;
217 | *TriFan++ = 75;
218 | *TriFan++ = 265;
219 | *TriFan++ = 40;
220 | *TriFan++ = 300;
221 | *TriFan++ = 25;
222 | *TriFan++ = 335;
223 | *TriFan++ = 40;
224 | *TriFan++ = 365;
225 | *TriFan++ = 75;
226 | *TriFan++ = 375;
227 | *TriFan++ = 100;
228 |
229 | White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
230 | Black = GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00);
231 | Red = GS_SETREG_RGBAQ(0xFF,0x00,0x00,0x00,0x00);
232 | Green = GS_SETREG_RGBAQ(0x00,0xFF,0x00,0x00,0x00);
233 | Blue = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x00,0x00);
234 |
235 | BlueTrans = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x40,0x00);
236 | RedTrans = GS_SETREG_RGBAQ(0xFF,0x00,0x00,0x60,0x00);
237 | GreenTrans = GS_SETREG_RGBAQ(0x00,0xFF,0x00,0x50,0x00);
238 | WhiteTrans = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x50,0x00);
239 |
240 | gsKit_mode_switch(gsGlobal, GS_PERSISTENT);
241 |
242 | gsKit_clear(gsGlobal, White);
243 |
244 | gsKit_set_test(gsGlobal, GS_ZTEST_OFF);
245 |
246 | gsKit_prim_line_strip(gsGlobal, LineStripPtr, 6, 1, Black);
247 |
248 | gsKit_prim_triangle_strip(gsGlobal, TriStripPtr, 6, 1, Red);
249 |
250 | gsKit_prim_line(gsGlobal, 525.0f, 125.0f, 575.0f, 125.0f, 1, Black);
251 | gsKit_prim_line(gsGlobal, 550.0f, 150.0f, 600.0f, 100.0f, 1, Black);
252 |
253 | gsKit_prim_point(gsGlobal, 575.0f, 75.0f, 1, Black);
254 | gsKit_prim_point(gsGlobal, 600.0f, 100.0f, 1, Black);
255 | gsKit_prim_point(gsGlobal, 625.0f, 125.0f, 1, Black);
256 |
257 | gsKit_prim_quad(gsGlobal, 150.0f, 150.0f,
258 | 150.0f, 400.0f,
259 | 450.0f, 150.0f,
260 | 450.0f, 400.0f, 2, Green);
261 |
262 | gsKit_set_test(gsGlobal, GS_ZTEST_ON);
263 |
264 | gsKit_prim_triangle_fan(gsGlobal, TriFanPtr, 8, 5, Black);
265 |
266 | gsKit_prim_quad_gouraud(gsGlobal, 500.0f, 250.0f,
267 | 500.0f, 350.0f,
268 | 600.0f, 250.0f,
269 | 600.0f, 350.0f, 2,
270 | Red, Green, Blue, Black);
271 |
272 | gsKit_prim_triangle_gouraud(gsGlobal, 280.0f, 200.0f,
273 | 280.0f, 350.0f,
274 | 180.0f, 350.0f, 5,
275 | Blue, Red, White);
276 |
277 | gsKit_prim_triangle(gsGlobal, 300.0f, 200.0f, 300.0f, 350.0f, 400.0f, 350.0f, 3, Red);
278 |
279 | gsKit_prim_sprite(gsGlobal, 400.0f, 100.0f, 500.0f, 200.0f, 5, Red);
280 |
281 | gsKit_mode_switch(gsGlobal, GS_ONESHOT);
282 |
283 |
284 | render_frame();
285 |
286 | printf("We have managed to render %d frames in %d vsyncs in PAL mode\n", frame_num, vsync_num);
287 |
288 | gsGlobal->Mode = GS_MODE_NTSC;
289 | gsGlobal->Interlace = GS_INTERLACED;
290 | gsGlobal->Field = GS_FIELD;
291 | gsGlobal->Width = 640;
292 | gsGlobal->Height = 448;
293 | vsync_max = 60;
294 | frame_num = 0;
295 |
296 | gsKit_init_screen(gsGlobal);
297 |
298 | render_frame();
299 |
300 | printf("We have managed to render %d frames in %d vsyncs in NTSC mode\n", frame_num, vsync_num);
301 |
302 |
303 | return 0;
304 | }
305 |
--------------------------------------------------------------------------------
/gsKit.pc.cmakein:
--------------------------------------------------------------------------------
1 | prefix=@CMAKE_INSTALL_PREFIX@
2 | exec_prefix=@CMAKE_INSTALL_PREFIX@
3 | libdir=@INSTALL_LIB_DIR@
4 | sharedlibdir=@INSTALL_LIB_DIR@
5 | includedir=@INSTALL_INC_DIR@
6 |
7 | Name: @PCKEY_NAME@
8 | Description: @PCKEY_DESCRIPTION@
9 | Version: @PCKEY_VERSION@
10 |
11 | Requires: @PCKEY_REQUIRES@
12 | Libs: @PCKEY_LIBS@
13 | Cflags: @PCKEY_CFLAGS@
14 |
--------------------------------------------------------------------------------
/setup.sh:
--------------------------------------------------------------------------------
1 | #! /bin/sh
2 |
3 | echo "Welcome to the setup script for gsKit."
4 | echo "This script will attempt to automatically detect the presence of LIBPNG, LIBJPEG, LIBTIFF and ZLIB, and will set up all required environmental variables."
5 | echo "If your libraries are not stored in $PS2SDK/ports, please specify the location of the libraries manually."
6 |
7 | ## Determine GNU Make command.
8 | if command -v gmake >/dev/null; then
9 | GNUMAKE=gmake
10 | else
11 | GNUMAKE=make
12 | fi
13 |
14 | echo "Performing pre-install cleanup."
15 | $GNUMAKE clean --silent
16 |
17 | echo "Libraries:"
18 |
19 | if [ -f "$PS2SDK/ports/include/jpeglib.h" ];
20 | then
21 | echo -e "\tLIBJPEG detected."
22 | export LIBJPEG=$PS2SDK/ports
23 | else
24 | echo -e "\tLIBJPEG not detected."
25 | fi
26 |
27 | if [ -f "$PS2SDK/ports/include/png.h" ];
28 | then
29 | echo -e "\tLIBPNG detected."
30 | export LIBPNG=$PS2SDK/ports
31 | else
32 | echo -e "\tLIBPNG not detected."
33 | fi
34 |
35 | if [ -f "$PS2SDK/ports/include/zlib.h" ];
36 | then
37 | echo -e "\tZLIB detected."
38 | export ZLIB=$PS2SDK/ports
39 | else
40 | echo -e "\tZLIB not detected."
41 | fi
42 |
43 | if [ -f "$PS2SDK/ports/include/tiff.h" ];
44 | then
45 | echo -e "\tLIBTIFF detected."
46 | export LIBTIFF=$PS2SDK/ports
47 | else
48 | echo -e "\tLIBTIFF not detected."
49 | fi
50 |
51 | echo "Building gsKit."
52 | $GNUMAKE --silent
53 | echo "Installing gsKit."
54 | $GNUMAKE install --silent
55 | echo "Performing post-install cleanup."
56 | $GNUMAKE clean --silent
57 |
--------------------------------------------------------------------------------