From 1aa0e17df7c325a41de8cf8a57f52ed853f08bf3 Mon Sep 17 00:00:00 2001 From: "John Wilbert M. Villamor" Date: Fri, 24 Apr 2020 19:01:28 +0800 Subject: Refined toolchain instructions, organized examples, added automatic retry for CdRead(), added FIOCSCAN ioctl in psxsio TTY driver, added tty and console examples. --- examples/balls/ball16c.h | 16 - examples/balls/ball16c.tim | Bin 192 -> 0 bytes examples/balls/main.c | 228 - examples/balls/makefile | 60 - examples/beginner/hello/main.c | 118 + examples/beginner/hello/makefile | 60 + examples/billboard/billboard.c | 260 - examples/billboard/makefile | 39 - examples/billboard/texture64.tim | Bin 2112 -> 0 bytes examples/billboard/tim.s | 7 - examples/cartrom/bios.inc | 67 - examples/cartrom/cop0.inc | 11 - examples/cartrom/makefile | 14 - examples/cartrom/parse.inc | 113 - examples/cartrom/readme.txt | 74 - examples/cartrom/rom.ld | 11 - examples/cartrom/rom.s | 399 -- examples/cdbrowse/ball16c.h | 16 - examples/cdbrowse/iso.xml | 33 - examples/cdbrowse/main.c | 517 -- examples/cdbrowse/makefile | 59 - examples/cdbrowse/system.cnf | 4 - examples/cdrom/cdbrowse/ball16c.h | 16 + examples/cdrom/cdbrowse/iso.xml | 33 + examples/cdrom/cdbrowse/main.c | 517 ++ examples/cdrom/cdbrowse/makefile | 52 + examples/cdrom/cdbrowse/system.cnf | 4 + examples/cdrom/cdxa/ball16c.h | 16 + examples/cdrom/cdxa/iso.xml | 29 + examples/cdrom/cdxa/main.c | 551 ++ examples/cdrom/cdxa/makefile | 52 + examples/cdrom/cdxa/system.cnf | 4 + examples/cdxa/ball16c.h | 16 - examples/cdxa/iso.xml | 29 - examples/cdxa/main.c | 551 -- examples/cdxa/makefile | 59 - examples/cdxa/system.cnf | 4 - examples/childexec/ball16c.h | 16 - examples/childexec/child.c | 319 -- examples/childexec/child_exe.s | 6 - examples/childexec/makefile | 38 - examples/childexec/parent.c | 305 -- examples/demos/n00bdemo/data.h | 12 + examples/demos/n00bdemo/data.s | 31 + examples/demos/n00bdemo/data.xml | 49 + examples/demos/n00bdemo/data/bulb.smd | Bin 0 -> 1708 bytes examples/demos/n00bdemo/data/bulb.smx | 147 + examples/demos/n00bdemo/data/bungirl.smd | Bin 0 -> 67532 bytes examples/demos/n00bdemo/data/bungirl.smx | 5608 +++++++++++++++++++++ examples/demos/n00bdemo/data/bungirl.tim | Bin 0 -> 16928 bytes examples/demos/n00bdemo/data/celmapi.bmp | Bin 0 -> 3126 bytes examples/demos/n00bdemo/data/celmapi.tim | Bin 0 -> 576 bytes examples/demos/n00bdemo/data/clktower.tim | Bin 0 -> 832 bytes examples/demos/n00bdemo/data/font.bmp | Bin 0 -> 12406 bytes examples/demos/n00bdemo/data/font.tim | Bin 0 -> 12352 bytes examples/demos/n00bdemo/data/hatkid.png | Bin 0 -> 390 bytes examples/demos/n00bdemo/data/hatkid.smd | Bin 0 -> 15676 bytes examples/demos/n00bdemo/data/hatkid.smx | 1281 +++++ examples/demos/n00bdemo/data/hatkid.tim | Bin 0 -> 576 bytes examples/demos/n00bdemo/data/lamelotl16c.png | Bin 0 -> 5777 bytes examples/demos/n00bdemo/data/lamelotl16c.tim | Bin 0 -> 24640 bytes examples/demos/n00bdemo/data/lightworld.smd | Bin 0 -> 13700 bytes examples/demos/n00bdemo/data/lightworld.smx | 1097 ++++ examples/demos/n00bdemo/data/logo.smd | Bin 0 -> 13524 bytes examples/demos/n00bdemo/data/logo.smx | 1169 +++++ examples/demos/n00bdemo/data/mtekdisk.smd | Bin 0 -> 4204 bytes examples/demos/n00bdemo/data/mtekdisk.smx | 379 ++ examples/demos/n00bdemo/data/mtektext.smd | Bin 0 -> 7172 bytes examples/demos/n00bdemo/data/mtektext.smx | 671 +++ examples/demos/n00bdemo/data/n00blogo-pixel.png | Bin 0 -> 1035 bytes examples/demos/n00bdemo/data/n00blogo-pixel.tim | Bin 0 -> 3392 bytes examples/demos/n00bdemo/data/petscum.smd | Bin 0 -> 13844 bytes examples/demos/n00bdemo/data/petscum.smx | 1093 ++++ examples/demos/n00bdemo/data/petscum16c.png | Bin 0 -> 955 bytes examples/demos/n00bdemo/data/petscum16c.tim | Bin 0 -> 5184 bytes examples/demos/n00bdemo/data/psn00blogo.smd | Bin 0 -> 8612 bytes examples/demos/n00bdemo/data/psn00blogo.smx | 745 +++ examples/demos/n00bdemo/data/rbowshade.smd | Bin 0 -> 676 bytes examples/demos/n00bdemo/data/rbowshade.smx | 50 + examples/demos/n00bdemo/data/riftbld1.tim | Bin 0 -> 1088 bytes examples/demos/n00bdemo/data/riftbld2.tim | Bin 0 -> 1088 bytes examples/demos/n00bdemo/data/star.smd | Bin 0 -> 220 bytes examples/demos/n00bdemo/data/star.smx | 26 + examples/demos/n00bdemo/data/star_mask.smd | Bin 0 -> 220 bytes examples/demos/n00bdemo/data/star_mask.smx | 25 + examples/demos/n00bdemo/data/timerift.smd | Bin 0 -> 16232 bytes examples/demos/n00bdemo/data/timerift.smx | 1085 ++++ examples/demos/n00bdemo/disp.c | 72 + examples/demos/n00bdemo/disp.h | 25 + examples/demos/n00bdemo/lightdemo.c | 494 ++ examples/demos/n00bdemo/logo.c | 428 ++ examples/demos/n00bdemo/logo.h | 6 + examples/demos/n00bdemo/main.c | 650 +++ examples/demos/n00bdemo/makefile | 44 + examples/demos/n00bdemo/overlay.c | 199 + examples/demos/n00bdemo/plasma_tbl.c | 500 ++ examples/demos/n00bdemo/plasma_tbl.h | 9 + examples/demos/n00bdemo/plasmagen.s | 181 + examples/demos/n00bdemo/scrolltext.c | 136 + examples/demos/n00bdemo/smd.h | 68 + examples/demos/n00bdemo/smd.s | 924 ++++ examples/demos/n00bdemo/smd_cel.s | 1073 ++++ examples/demos/n00bdemo/smd_flat.s | 832 +++ examples/demos/n00bdemo/smd_s.h | 336 ++ examples/demos/n00bdemo/smdparser.s | 129 + examples/fpscam/clip.c | 108 - examples/fpscam/clip.h | 27 - examples/fpscam/lookat.c | 40 - examples/fpscam/lookat.h | 19 - examples/fpscam/main.c | 678 --- examples/fpscam/makefile | 39 - examples/graphics/balls/ball16c.h | 16 + examples/graphics/balls/ball16c.tim | Bin 0 -> 192 bytes examples/graphics/balls/main.c | 228 + examples/graphics/balls/makefile | 60 + examples/graphics/billboard/billboard.c | 260 + examples/graphics/billboard/makefile | 39 + examples/graphics/billboard/texture64.tim | Bin 0 -> 2112 bytes examples/graphics/billboard/tim.s | 7 + examples/graphics/fpscam/clip.c | 108 + examples/graphics/fpscam/clip.h | 27 + examples/graphics/fpscam/lookat.c | 40 + examples/graphics/fpscam/lookat.h | 19 + examples/graphics/fpscam/main.c | 678 +++ examples/graphics/fpscam/makefile | 39 + examples/graphics/gte/main.c | 313 ++ examples/graphics/gte/makefile | 39 + examples/graphics/render2tex/blendpattern-16c.png | Bin 0 -> 385 bytes examples/graphics/render2tex/blendpattern-16c.tim | Bin 0 -> 2112 bytes examples/graphics/render2tex/blendpattern.png | Bin 0 -> 826 bytes examples/graphics/render2tex/main.c | 649 +++ examples/graphics/render2tex/makefile | 39 + examples/graphics/render2tex/texture.s | 9 + examples/graphics/rgb24/bunpattern.tim | Bin 0 -> 921620 bytes examples/graphics/rgb24/main.c | 52 + examples/graphics/rgb24/makefile | 41 + examples/graphics/rgb24/tim.s | 7 + examples/gte/main.c | 313 -- examples/gte/makefile | 39 - examples/hello/main.c | 118 - examples/hello/makefile | 60 - examples/lowlevel/cartrom/bios.inc | 67 + examples/lowlevel/cartrom/cop0.inc | 11 + examples/lowlevel/cartrom/makefile | 14 + examples/lowlevel/cartrom/parse.inc | 113 + examples/lowlevel/cartrom/readme.txt | 74 + examples/lowlevel/cartrom/rom.ld | 11 + examples/lowlevel/cartrom/rom.s | 399 ++ examples/makefile | 20 +- examples/n00bdemo/data.h | 12 - examples/n00bdemo/data.s | 31 - examples/n00bdemo/data.xml | 49 - examples/n00bdemo/data/bulb.smd | Bin 1708 -> 0 bytes examples/n00bdemo/data/bulb.smx | 147 - examples/n00bdemo/data/bungirl.smd | Bin 67532 -> 0 bytes examples/n00bdemo/data/bungirl.smx | 5608 --------------------- examples/n00bdemo/data/bungirl.tim | Bin 16928 -> 0 bytes examples/n00bdemo/data/celmapi.bmp | Bin 3126 -> 0 bytes examples/n00bdemo/data/celmapi.tim | Bin 576 -> 0 bytes examples/n00bdemo/data/clktower.tim | Bin 832 -> 0 bytes examples/n00bdemo/data/font.bmp | Bin 12406 -> 0 bytes examples/n00bdemo/data/font.tim | Bin 12352 -> 0 bytes examples/n00bdemo/data/hatkid.png | Bin 390 -> 0 bytes examples/n00bdemo/data/hatkid.smd | Bin 15676 -> 0 bytes examples/n00bdemo/data/hatkid.smx | 1281 ----- examples/n00bdemo/data/hatkid.tim | Bin 576 -> 0 bytes examples/n00bdemo/data/lamelotl16c.png | Bin 5777 -> 0 bytes examples/n00bdemo/data/lamelotl16c.tim | Bin 24640 -> 0 bytes examples/n00bdemo/data/lightworld.smd | Bin 13700 -> 0 bytes examples/n00bdemo/data/lightworld.smx | 1097 ---- examples/n00bdemo/data/logo.smd | Bin 13524 -> 0 bytes examples/n00bdemo/data/logo.smx | 1169 ----- examples/n00bdemo/data/mtekdisk.smd | Bin 4204 -> 0 bytes examples/n00bdemo/data/mtekdisk.smx | 379 -- examples/n00bdemo/data/mtektext.smd | Bin 7172 -> 0 bytes examples/n00bdemo/data/mtektext.smx | 671 --- examples/n00bdemo/data/n00blogo-pixel.png | Bin 1035 -> 0 bytes examples/n00bdemo/data/n00blogo-pixel.tim | Bin 3392 -> 0 bytes examples/n00bdemo/data/petscum.smd | Bin 13844 -> 0 bytes examples/n00bdemo/data/petscum.smx | 1093 ---- examples/n00bdemo/data/petscum16c.png | Bin 955 -> 0 bytes examples/n00bdemo/data/petscum16c.tim | Bin 5184 -> 0 bytes examples/n00bdemo/data/psn00blogo.smd | Bin 8612 -> 0 bytes examples/n00bdemo/data/psn00blogo.smx | 745 --- examples/n00bdemo/data/rbowshade.smd | Bin 676 -> 0 bytes examples/n00bdemo/data/rbowshade.smx | 50 - examples/n00bdemo/data/riftbld1.tim | Bin 1088 -> 0 bytes examples/n00bdemo/data/riftbld2.tim | Bin 1088 -> 0 bytes examples/n00bdemo/data/star.smd | Bin 220 -> 0 bytes examples/n00bdemo/data/star.smx | 26 - examples/n00bdemo/data/star_mask.smd | Bin 220 -> 0 bytes examples/n00bdemo/data/star_mask.smx | 25 - examples/n00bdemo/data/timerift.smd | Bin 16232 -> 0 bytes examples/n00bdemo/data/timerift.smx | 1085 ---- examples/n00bdemo/disp.c | 72 - examples/n00bdemo/disp.h | 25 - examples/n00bdemo/lightdemo.c | 494 -- examples/n00bdemo/logo.c | 428 -- examples/n00bdemo/logo.h | 6 - examples/n00bdemo/main.c | 650 --- examples/n00bdemo/makefile | 45 - examples/n00bdemo/overlay.c | 199 - examples/n00bdemo/plasma_tbl.c | 500 -- examples/n00bdemo/plasma_tbl.h | 9 - examples/n00bdemo/plasmagen.s | 181 - examples/n00bdemo/scrolltext.c | 136 - examples/n00bdemo/smd.h | 68 - examples/n00bdemo/smd.s | 924 ---- examples/n00bdemo/smd_cel.s | 1073 ---- examples/n00bdemo/smd_flat.s | 832 --- examples/n00bdemo/smd_s.h | 336 -- examples/n00bdemo/smdparser.s | 129 - examples/render2tex/blendpattern-16c.png | Bin 385 -> 0 bytes examples/render2tex/blendpattern-16c.tim | Bin 2112 -> 0 bytes examples/render2tex/blendpattern.png | Bin 826 -> 0 bytes examples/render2tex/main.c | 649 --- examples/render2tex/makefile | 39 - examples/render2tex/texture.s | 9 - examples/rgb24/bunpattern.tim | Bin 921620 -> 0 bytes examples/rgb24/main.c | 52 - examples/rgb24/makefile | 41 - examples/rgb24/tim.s | 7 - examples/sdk-common.mk | 4 +- examples/system/childexec/ball16c.h | 16 + examples/system/childexec/child.c | 319 ++ examples/system/childexec/child_exe.s | 6 + examples/system/childexec/makefile | 38 + examples/system/childexec/parent.c | 305 ++ examples/system/console/ball16c.h | 16 + examples/system/console/main.c | 284 ++ examples/system/console/makefile | 60 + examples/system/timer/main.c | 154 + examples/system/timer/makefile | 39 + examples/system/tty/main.c | 145 + examples/system/tty/makefile | 60 + examples/timer/main.c | 154 - examples/timer/makefile | 39 - 237 files changed, 25847 insertions(+), 25281 deletions(-) delete mode 100644 examples/balls/ball16c.h delete mode 100644 examples/balls/ball16c.tim delete mode 100644 examples/balls/main.c delete mode 100644 examples/balls/makefile create mode 100644 examples/beginner/hello/main.c create mode 100644 examples/beginner/hello/makefile delete mode 100644 examples/billboard/billboard.c delete mode 100644 examples/billboard/makefile delete mode 100644 examples/billboard/texture64.tim delete mode 100644 examples/billboard/tim.s delete mode 100644 examples/cartrom/bios.inc delete mode 100644 examples/cartrom/cop0.inc delete mode 100644 examples/cartrom/makefile delete mode 100644 examples/cartrom/parse.inc delete mode 100644 examples/cartrom/readme.txt delete mode 100644 examples/cartrom/rom.ld delete mode 100644 examples/cartrom/rom.s delete mode 100644 examples/cdbrowse/ball16c.h delete mode 100644 examples/cdbrowse/iso.xml delete mode 100644 examples/cdbrowse/main.c delete mode 100644 examples/cdbrowse/makefile delete mode 100644 examples/cdbrowse/system.cnf create mode 100644 examples/cdrom/cdbrowse/ball16c.h create mode 100644 examples/cdrom/cdbrowse/iso.xml create mode 100644 examples/cdrom/cdbrowse/main.c create mode 100644 examples/cdrom/cdbrowse/makefile create mode 100644 examples/cdrom/cdbrowse/system.cnf create mode 100644 examples/cdrom/cdxa/ball16c.h create mode 100644 examples/cdrom/cdxa/iso.xml create mode 100644 examples/cdrom/cdxa/main.c create mode 100644 examples/cdrom/cdxa/makefile create mode 100644 examples/cdrom/cdxa/system.cnf delete mode 100644 examples/cdxa/ball16c.h delete mode 100644 examples/cdxa/iso.xml delete mode 100644 examples/cdxa/main.c delete mode 100644 examples/cdxa/makefile delete mode 100644 examples/cdxa/system.cnf delete mode 100644 examples/childexec/ball16c.h delete mode 100644 examples/childexec/child.c delete mode 100644 examples/childexec/child_exe.s delete mode 100644 examples/childexec/makefile delete mode 100644 examples/childexec/parent.c create mode 100644 examples/demos/n00bdemo/data.h create mode 100644 examples/demos/n00bdemo/data.s create mode 100644 examples/demos/n00bdemo/data.xml create mode 100644 examples/demos/n00bdemo/data/bulb.smd create mode 100644 examples/demos/n00bdemo/data/bulb.smx create mode 100644 examples/demos/n00bdemo/data/bungirl.smd create mode 100644 examples/demos/n00bdemo/data/bungirl.smx create mode 100644 examples/demos/n00bdemo/data/bungirl.tim create mode 100644 examples/demos/n00bdemo/data/celmapi.bmp create mode 100644 examples/demos/n00bdemo/data/celmapi.tim create mode 100644 examples/demos/n00bdemo/data/clktower.tim create mode 100644 examples/demos/n00bdemo/data/font.bmp create mode 100644 examples/demos/n00bdemo/data/font.tim create mode 100644 examples/demos/n00bdemo/data/hatkid.png create mode 100644 examples/demos/n00bdemo/data/hatkid.smd create mode 100644 examples/demos/n00bdemo/data/hatkid.smx create mode 100644 examples/demos/n00bdemo/data/hatkid.tim create mode 100644 examples/demos/n00bdemo/data/lamelotl16c.png create mode 100644 examples/demos/n00bdemo/data/lamelotl16c.tim create mode 100644 examples/demos/n00bdemo/data/lightworld.smd create mode 100644 examples/demos/n00bdemo/data/lightworld.smx create mode 100644 examples/demos/n00bdemo/data/logo.smd create mode 100644 examples/demos/n00bdemo/data/logo.smx create mode 100644 examples/demos/n00bdemo/data/mtekdisk.smd create mode 100644 examples/demos/n00bdemo/data/mtekdisk.smx create mode 100644 examples/demos/n00bdemo/data/mtektext.smd create mode 100644 examples/demos/n00bdemo/data/mtektext.smx create mode 100644 examples/demos/n00bdemo/data/n00blogo-pixel.png create mode 100644 examples/demos/n00bdemo/data/n00blogo-pixel.tim create mode 100644 examples/demos/n00bdemo/data/petscum.smd create mode 100644 examples/demos/n00bdemo/data/petscum.smx create mode 100644 examples/demos/n00bdemo/data/petscum16c.png create mode 100644 examples/demos/n00bdemo/data/petscum16c.tim create mode 100644 examples/demos/n00bdemo/data/psn00blogo.smd create mode 100644 examples/demos/n00bdemo/data/psn00blogo.smx create mode 100644 examples/demos/n00bdemo/data/rbowshade.smd create mode 100644 examples/demos/n00bdemo/data/rbowshade.smx create mode 100644 examples/demos/n00bdemo/data/riftbld1.tim create mode 100644 examples/demos/n00bdemo/data/riftbld2.tim create mode 100644 examples/demos/n00bdemo/data/star.smd create mode 100644 examples/demos/n00bdemo/data/star.smx create mode 100644 examples/demos/n00bdemo/data/star_mask.smd create mode 100644 examples/demos/n00bdemo/data/star_mask.smx create mode 100644 examples/demos/n00bdemo/data/timerift.smd create mode 100644 examples/demos/n00bdemo/data/timerift.smx create mode 100644 examples/demos/n00bdemo/disp.c create mode 100644 examples/demos/n00bdemo/disp.h create mode 100644 examples/demos/n00bdemo/lightdemo.c create mode 100644 examples/demos/n00bdemo/logo.c create mode 100644 examples/demos/n00bdemo/logo.h create mode 100644 examples/demos/n00bdemo/main.c create mode 100644 examples/demos/n00bdemo/makefile create mode 100644 examples/demos/n00bdemo/overlay.c create mode 100644 examples/demos/n00bdemo/plasma_tbl.c create mode 100644 examples/demos/n00bdemo/plasma_tbl.h create mode 100644 examples/demos/n00bdemo/plasmagen.s create mode 100644 examples/demos/n00bdemo/scrolltext.c create mode 100644 examples/demos/n00bdemo/smd.h create mode 100644 examples/demos/n00bdemo/smd.s create mode 100644 examples/demos/n00bdemo/smd_cel.s create mode 100644 examples/demos/n00bdemo/smd_flat.s create mode 100644 examples/demos/n00bdemo/smd_s.h create mode 100644 examples/demos/n00bdemo/smdparser.s delete mode 100644 examples/fpscam/clip.c delete mode 100644 examples/fpscam/clip.h delete mode 100644 examples/fpscam/lookat.c delete mode 100644 examples/fpscam/lookat.h delete mode 100644 examples/fpscam/main.c delete mode 100644 examples/fpscam/makefile create mode 100644 examples/graphics/balls/ball16c.h create mode 100644 examples/graphics/balls/ball16c.tim create mode 100644 examples/graphics/balls/main.c create mode 100644 examples/graphics/balls/makefile create mode 100644 examples/graphics/billboard/billboard.c create mode 100644 examples/graphics/billboard/makefile create mode 100644 examples/graphics/billboard/texture64.tim create mode 100644 examples/graphics/billboard/tim.s create mode 100644 examples/graphics/fpscam/clip.c create mode 100644 examples/graphics/fpscam/clip.h create mode 100644 examples/graphics/fpscam/lookat.c create mode 100644 examples/graphics/fpscam/lookat.h create mode 100644 examples/graphics/fpscam/main.c create mode 100644 examples/graphics/fpscam/makefile create mode 100644 examples/graphics/gte/main.c create mode 100644 examples/graphics/gte/makefile create mode 100644 examples/graphics/render2tex/blendpattern-16c.png create mode 100644 examples/graphics/render2tex/blendpattern-16c.tim create mode 100644 examples/graphics/render2tex/blendpattern.png create mode 100644 examples/graphics/render2tex/main.c create mode 100644 examples/graphics/render2tex/makefile create mode 100644 examples/graphics/render2tex/texture.s create mode 100644 examples/graphics/rgb24/bunpattern.tim create mode 100644 examples/graphics/rgb24/main.c create mode 100644 examples/graphics/rgb24/makefile create mode 100644 examples/graphics/rgb24/tim.s delete mode 100644 examples/gte/main.c delete mode 100644 examples/gte/makefile delete mode 100644 examples/hello/main.c delete mode 100644 examples/hello/makefile create mode 100644 examples/lowlevel/cartrom/bios.inc create mode 100644 examples/lowlevel/cartrom/cop0.inc create mode 100644 examples/lowlevel/cartrom/makefile create mode 100644 examples/lowlevel/cartrom/parse.inc create mode 100644 examples/lowlevel/cartrom/readme.txt create mode 100644 examples/lowlevel/cartrom/rom.ld create mode 100644 examples/lowlevel/cartrom/rom.s delete mode 100644 examples/n00bdemo/data.h delete mode 100644 examples/n00bdemo/data.s delete mode 100644 examples/n00bdemo/data.xml delete mode 100644 examples/n00bdemo/data/bulb.smd delete mode 100644 examples/n00bdemo/data/bulb.smx delete mode 100644 examples/n00bdemo/data/bungirl.smd delete mode 100644 examples/n00bdemo/data/bungirl.smx delete mode 100644 examples/n00bdemo/data/bungirl.tim delete mode 100644 examples/n00bdemo/data/celmapi.bmp delete mode 100644 examples/n00bdemo/data/celmapi.tim delete mode 100644 examples/n00bdemo/data/clktower.tim delete mode 100644 examples/n00bdemo/data/font.bmp delete mode 100644 examples/n00bdemo/data/font.tim delete mode 100644 examples/n00bdemo/data/hatkid.png delete mode 100644 examples/n00bdemo/data/hatkid.smd delete mode 100644 examples/n00bdemo/data/hatkid.smx delete mode 100644 examples/n00bdemo/data/hatkid.tim delete mode 100644 examples/n00bdemo/data/lamelotl16c.png delete mode 100644 examples/n00bdemo/data/lamelotl16c.tim delete mode 100644 examples/n00bdemo/data/lightworld.smd delete mode 100644 examples/n00bdemo/data/lightworld.smx delete mode 100644 examples/n00bdemo/data/logo.smd delete mode 100644 examples/n00bdemo/data/logo.smx delete mode 100644 examples/n00bdemo/data/mtekdisk.smd delete mode 100644 examples/n00bdemo/data/mtekdisk.smx delete mode 100644 examples/n00bdemo/data/mtektext.smd delete mode 100644 examples/n00bdemo/data/mtektext.smx delete mode 100644 examples/n00bdemo/data/n00blogo-pixel.png delete mode 100644 examples/n00bdemo/data/n00blogo-pixel.tim delete mode 100644 examples/n00bdemo/data/petscum.smd delete mode 100644 examples/n00bdemo/data/petscum.smx delete mode 100644 examples/n00bdemo/data/petscum16c.png delete mode 100644 examples/n00bdemo/data/petscum16c.tim delete mode 100644 examples/n00bdemo/data/psn00blogo.smd delete mode 100644 examples/n00bdemo/data/psn00blogo.smx delete mode 100644 examples/n00bdemo/data/rbowshade.smd delete mode 100644 examples/n00bdemo/data/rbowshade.smx delete mode 100644 examples/n00bdemo/data/riftbld1.tim delete mode 100644 examples/n00bdemo/data/riftbld2.tim delete mode 100644 examples/n00bdemo/data/star.smd delete mode 100644 examples/n00bdemo/data/star.smx delete mode 100644 examples/n00bdemo/data/star_mask.smd delete mode 100644 examples/n00bdemo/data/star_mask.smx delete mode 100644 examples/n00bdemo/data/timerift.smd delete mode 100644 examples/n00bdemo/data/timerift.smx delete mode 100644 examples/n00bdemo/disp.c delete mode 100644 examples/n00bdemo/disp.h delete mode 100644 examples/n00bdemo/lightdemo.c delete mode 100644 examples/n00bdemo/logo.c delete mode 100644 examples/n00bdemo/logo.h delete mode 100644 examples/n00bdemo/main.c delete mode 100644 examples/n00bdemo/makefile delete mode 100644 examples/n00bdemo/overlay.c delete mode 100644 examples/n00bdemo/plasma_tbl.c delete mode 100644 examples/n00bdemo/plasma_tbl.h delete mode 100644 examples/n00bdemo/plasmagen.s delete mode 100644 examples/n00bdemo/scrolltext.c delete mode 100644 examples/n00bdemo/smd.h delete mode 100644 examples/n00bdemo/smd.s delete mode 100644 examples/n00bdemo/smd_cel.s delete mode 100644 examples/n00bdemo/smd_flat.s delete mode 100644 examples/n00bdemo/smd_s.h delete mode 100644 examples/n00bdemo/smdparser.s delete mode 100644 examples/render2tex/blendpattern-16c.png delete mode 100644 examples/render2tex/blendpattern-16c.tim delete mode 100644 examples/render2tex/blendpattern.png delete mode 100644 examples/render2tex/main.c delete mode 100644 examples/render2tex/makefile delete mode 100644 examples/render2tex/texture.s delete mode 100644 examples/rgb24/bunpattern.tim delete mode 100644 examples/rgb24/main.c delete mode 100644 examples/rgb24/makefile delete mode 100644 examples/rgb24/tim.s create mode 100644 examples/system/childexec/ball16c.h create mode 100644 examples/system/childexec/child.c create mode 100644 examples/system/childexec/child_exe.s create mode 100644 examples/system/childexec/makefile create mode 100644 examples/system/childexec/parent.c create mode 100644 examples/system/console/ball16c.h create mode 100644 examples/system/console/main.c create mode 100644 examples/system/console/makefile create mode 100644 examples/system/timer/main.c create mode 100644 examples/system/timer/makefile create mode 100644 examples/system/tty/main.c create mode 100644 examples/system/tty/makefile delete mode 100644 examples/timer/main.c delete mode 100644 examples/timer/makefile (limited to 'examples') diff --git a/examples/balls/ball16c.h b/examples/balls/ball16c.h deleted file mode 100644 index c79f273..0000000 --- a/examples/balls/ball16c.h +++ /dev/null @@ -1,16 +0,0 @@ -unsigned int ball16c_size=192; -unsigned char ball16c[] = { -0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, -0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, -0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, -0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, -0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, -0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, -0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, -0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, -0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, -0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, -0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, -0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, -0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 -}; diff --git a/examples/balls/ball16c.tim b/examples/balls/ball16c.tim deleted file mode 100644 index e2a5d17..0000000 Binary files a/examples/balls/ball16c.tim and /dev/null differ diff --git a/examples/balls/main.c b/examples/balls/main.c deleted file mode 100644 index 89c8063..0000000 --- a/examples/balls/main.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * LibPSn00b Example Programs - * - * Balls Example - * 2019 Meido-Tek Productions / PSn00bSDK Project - * - * Draws a bunch of ball sprites that bounce around the screen, - * along with a ball snake that might be difficult to see. - * - * - * Example by Lameguy64 - * - * Changelog: - * - * November 20, 2018 - Initial version. - * - */ - -#include -#include -#include -#include -#include -#include "ball16c.h" - - -#define MAX_BALLS 1024 - -#define OT_LEN 8 - -#define SCREEN_XRES 640 -#define SCREEN_YRES 480 - -#define CENTER_X SCREEN_XRES/2 -#define CENTER_Y SCREEN_YRES/2 - - -/* Display and drawing environments */ -DISPENV disp; -DRAWENV draw; - -char pribuff[2][65536]; /* Primitive packet buffers */ -unsigned int ot[2][OT_LEN]; /* Ordering tables */ -char *nextpri; /* Pointer to next packet buffer offset */ -int db = 0; /* Double buffer index */ - - -/* Ball struct and array */ -typedef struct { - short x,y; - short xdir,ydir; - unsigned char r,g,b,p; -} BALL_TYPE; - -BALL_TYPE balls[MAX_BALLS]; - - -/* TIM image parameters for loading the ball texture and drawing sprites */ -TIM_IMAGE tim; - - -void init() { - - int i; - - /* Reset GPU (also installs event handler for VSync) */ - printf("Init GPU... "); - ResetGraph( 0 ); - printf("Done.\n"); - - - printf("Set video mode... "); - - /* Set display and draw environment parameters */ - SetDefDispEnv( &disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); - disp.isinter = 1; /* Enable interlace (required for hires) */ - - /* Set clear color, area clear and dither processing */ - setRGB0( &draw, 63, 0, 127 ); - draw.isbg = 1; - draw.dtd = 1; - - /* Apply the display and drawing environments */ - PutDispEnv( &disp ); - PutDrawEnv( &draw ); - - /* Enable video output */ - SetDispMask( 1 ); - - printf("Done.\n"); - - - /* Upload the ball texture */ - printf("Upload texture... "); - GetTimInfo( (unsigned int*)ball16c, &tim ); /* Get TIM parameters */ - - LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */ - if( tim.mode & 0x8 ) { - LoadImage( tim.crect, tim.caddr ); /* Upload CLUT if present */ - } - - printf("Done.\n"); - - - /* Calculate ball positions */ - printf("Calculating balls... "); - - for(i=0; i>5), - (CENTER_Y-8)-(icos((counter-(i<<2))<<3)>>5) ); - setRGB0( sprt, rand()%256, rand()%256, rand()%256 ); - setUV0( sprt, 0, 0 ); - setClut( sprt, tim.crect->x, tim.crect->y ); - - addPrim( ot[db]+(OT_LEN-1), sprt ); - sprt++; - - } - - /* Sort the balls */ - for( i=0; ix, tim.crect->y ); - - addPrim( ot[db]+(OT_LEN-1), sprt ); - sprt++; - - balls[i].x += balls[i].xdir; - balls[i].y += balls[i].ydir; - - if( ( balls[i].x+16 ) > 640 ) { - balls[i].xdir = -2; - } else if( balls[i].x < 0 ) { - balls[i].xdir = 2; - } - - if( ( balls[i].y+16 ) > 480 ) { - balls[i].ydir = -2; - } else if( balls[i].y < 0 ) { - balls[i].ydir = 2; - } - - } - nextpri = (char*)sprt; - - - /* Sort a TPage primitive so the sprites will draw pixels from */ - /* the correct texture page in VRAM */ - tpri = (DR_TPAGE*)nextpri; - setDrawTPage( tpri, 0, 0, - getTPage(0, 0, tim.prect->x, tim.prect->y )); - addPrim( ot[db]+(OT_LEN-1), tpri ); - nextpri += sizeof(DR_TPAGE); - - /* Wait for GPU and VSync */ - DrawSync( 0 ); - VSync( 0 ); - - /* Since draw.isbg is non-zero this clears the screen */ - PutDrawEnv( &draw ); - - /* Begin drawing the new frame */ - DrawOTag( ot[db]+(OT_LEN-1) ); - - /* Alternate to the next buffer */ - db = !db; - - /* Increment counter for the snake animation */ - counter++; - - } - - return 0; - -} diff --git a/examples/balls/makefile b/examples/balls/makefile deleted file mode 100644 index e0f6bc3..0000000 --- a/examples/balls/makefile +++ /dev/null @@ -1,60 +0,0 @@ -include ../sdk-common.mk - -# Project target name -TARGET = balls.elf - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Determine object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.o)) \ - $(addprefix build/,$(AFILES:.s=.o)) - -# Project specific include and library directories -# (use -I for include dirs, -L for library dirs) -INCLUDE += -LIBDIRS += - -# Libraries to link -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc - -# C compiler flags -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections - -# C++ compiler flags -CPPFLAGS = $(CFLAGS) -fno-exceptions - -# Assembler flags -AFLAGS = -g -msoft-float - -# Linker flags -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x - -# Toolchain programs -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -AS = $(PREFIX)as -LD = $(PREFIX)ld - -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/beginner/hello/main.c b/examples/beginner/hello/main.c new file mode 100644 index 0000000..1f02f0b --- /dev/null +++ b/examples/beginner/hello/main.c @@ -0,0 +1,118 @@ +/* + * LibPSn00b Example Programs + * + * Hello World Example + * 2019-2020 Meido-Tek Productions / PSn00bSDK Project + * + * The obligatory hello world example normally included in nearly every + * SDK package. This example should also get you started in how to manage + * the display using psxgpu. + * + * Example by Lameguy64 + * + * + * Changelog: + * + * January 1, 2020 - Initial version + */ + +#include +#include +#include +#include +#include + + +// Define display/draw environments for double buffering +DISPENV disp[2]; +DRAWENV draw[2]; +int db; + + +// Init function +void init(void) +{ + // This not only resets the GPU but it also installs the library's + // ISR subsystem to the kernel + ResetGraph(0); + + // Define display environments, first on top and second on bottom + SetDefDispEnv(&disp[0], 0, 0, 320, 240); + SetDefDispEnv(&disp[1], 0, 240, 320, 240); + + // Define drawing environments, first on bottom and second on top + SetDefDrawEnv(&draw[0], 0, 240, 320, 240); + SetDefDrawEnv(&draw[1], 0, 0, 320, 240); + + // Set and enable clear color + setRGB0(&draw[0], 0, 96, 0); + setRGB0(&draw[1], 0, 96, 0); + draw[0].isbg = 1; + draw[1].isbg = 1; + + // Clear double buffer counter + db = 0; + + // Apply the GPU environments + PutDispEnv(&disp[db]); + PutDrawEnv(&draw[db]); + + // Load test font + FntLoad(960, 0); + + // Open up a test font text stream of 100 characters + FntOpen(0, 8, 320, 224, 0, 100); +} + +// Display function +void display(void) +{ + // Flip buffer index + db = !db; + + // Wait for all drawing to complete + DrawSync(0); + + // Wait for vertical sync to cap the logic to 60fps (or 50 in PAL mode) + // and prevent screen tearing + VSync(0); + + // Switch pages + PutDispEnv(&disp[db]); + PutDrawEnv(&draw[db]); + + // Enable display output, ResetGraph() disables it by default + SetDispMask(1); + +} + +// Main function, program entrypoint +int main(int argc, const char *argv[]) +{ + int counter; + + // Init stuff + init(); + + // Main loop + counter = 0; + while(1) + { + + // Print the obligatory hello world and counter to show that the + // program isn't locking up to the last created text stream + FntPrint(-1, "HELLO WORLD\n"); + FntPrint(-1, "COUNTER=%d\n", counter); + + // Draw the last created text stream + FntFlush(-1); + + // Update display + display(); + + // Increment the counter + counter++; + } + + return 0; +} diff --git a/examples/beginner/hello/makefile b/examples/beginner/hello/makefile new file mode 100644 index 0000000..1893a48 --- /dev/null +++ b/examples/beginner/hello/makefile @@ -0,0 +1,60 @@ +include ../../sdk-common.mk + +# Project target name +TARGET = hello.elf + +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CPPFILES = $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +# Determine object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) + +# Project specific include and library directories +# (use -I for include dirs, -L for library dirs) +INCLUDE += +LIBDIRS += + +# Libraries to link +LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc + +# C compiler flags +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections + +# C++ compiler flags +CPPFLAGS = $(CFLAGS) -fno-exceptions + +# Assembler flags +AFLAGS = -g -msoft-float + +# Linker flags +LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ + -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x + +# Toolchain programs +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/billboard/billboard.c b/examples/billboard/billboard.c deleted file mode 100644 index bba5dda..0000000 --- a/examples/billboard/billboard.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * LibPSn00b Example Programs - * - * GTE Billboarding Sprites Example - * 2019 Meido-Tek Productions / PSn00bSDK Project - * - * Displays a bunch of sprites placed on the screen using 3D coordinates - * that scale according to the distance from the screen. This is a quick - * modification of the GTE cube example. - * - * Billboard sprites are useful for 2D projectiles flying across 3D space, - * particle effects such as smoke as well as characters and objects - * represented as 2D sprites. - * - * Example by Lameguy64 - * - * Changelog: - * - * Sep 24, 2019 - Initial version. - * - */ - -#include -#include -#include -#include - -/* OT and Packet Buffer sizes */ -#define OT_LEN 256 -#define PACKET_LEN 1024 - -/* Screen resolution */ -#define SCREEN_XRES 320 -#define SCREEN_YRES 240 - -/* Screen center position */ -#define CENTERX SCREEN_XRES>>1 -#define CENTERY SCREEN_YRES>>1 - - -/* Double buffer structure */ -typedef struct { - DISPENV disp; /* Display environment */ - DRAWENV draw; /* Drawing environment */ - int ot[OT_LEN]; /* Ordering table */ - char p[PACKET_LEN]; /* Packet buffer */ -} DB; - -/* Double buffer variables */ -DB db[2]; -int db_active = 0; -char *db_nextpri; - -extern int tim_image[]; -TIM_IMAGE tim; - -/* For easier handling of vertex indices */ -typedef struct { - short v0,v1,v2,v3; -} INDEX; - -/* Sprite position vertices */ -SVECTOR verts[] = { - { -50, -50, -50, 0 }, - { 50, -50, -50, 0 }, - { -50, 50, -50, 0 }, - { 50, 50, -50, 0 }, - { 50, -50, 50, 0 }, - { -50, -50, 50, 0 }, - { 50, 50, 50, 0 }, - { -50, 50, 50, 0 } -}; - - -/* Function declarations */ -void init(); -void display(); - - -/* Main function */ -int main() { - - int i,p,sz; - - SVECTOR rot = { 0 }; /* Rotation vector for Rotmatrix */ - VECTOR pos = { 0, 0, 160 }; /* Translation vector for TransMatrix */ - MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ - - POLY_FT4 *quad; /* Flat shaded quad primitive pointer */ - SVECTOR spos; - - /* Init graphics and GTE */ - init(); - - - /* Main loop */ - while( 1 ) { - - /* Set rotation and translation to the matrix */ - RotMatrix( &rot, &mtx ); - TransMatrix( &mtx, &pos ); - - /* Set rotation and translation matrix */ - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - /* Make the sprites revolve around */ - rot.vy += 16; - rot.vz += 16; - - /* Draw the sprites */ - quad = (POLY_FT4*)db_nextpri; - - for( i=0; i<8; i++ ) { - - // Load the 3D coordinate of the sprite to GTE - gte_ldv0(&verts[i]); - - // Rotation, Translation and Perspective Single - gte_rtps(); - - // Store depth - gte_stsz(&p); - - // Don't sort sprite if depth is zero - // (or divide by zero will happen later) - if( p > 0 ) { - - // Store result to position vector - gte_stsxy2(&spos); - - // Calculate sprite size, the divide operation might be a - // performance killer but it's likely faster than performing - // a lookat operation between sprite and camera, which some - // billboard sprite implementations use. - sz = (16*CENTERX)/p; - - // Prepare quad primitive - setPolyFT4(quad); - - // Set quad coordinates - setXY4(quad, - spos.vx-sz, spos.vy-sz, - spos.vx+sz, spos.vy-sz, - spos.vx-sz, spos.vy+sz, - spos.vx+sz, spos.vy+sz); - - // Set color - setRGB0(quad, 128, 128, 128); - - // Set tpage - quad->tpage = getTPage(tim.mode&0x8, 0, tim.prect->x, tim.prect->y); - - // Set CLUT - setClut(quad, tim.crect->x, tim.crect->y); - - // Set texture coordinates - setUVWH(quad, 0, 0, 64, 64); - - /* Sort primitive to the ordering table */ - addPrim(db[db_active].ot+(p>>2), quad); - - /* Advance to make another primitive */ - quad++; - - } - } - - /* Update nextpri variable */ - /* (IMPORTANT if you plan to sort more primitives after this) */ - db_nextpri = (char*)quad; - - /* Swap buffers and draw the primitives */ - display(); - - } - - return 0; - -} - -void init() { - - /* Reset the GPU, also installs a VSync event handler */ - ResetGraph( 0 ); - - /* Set display and draw environment areas */ - /* (display and draw areas must be separate, otherwise hello flicker) */ - SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - - /* Enable draw area clear and dither processing */ - setRGB0( &db[0].draw, 63, 0, 127 ); - db[0].draw.isbg = 1; - db[0].draw.dtd = 1; - - - /* Define the second set of display/draw environments */ - SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); - - setRGB0( &db[1].draw, 63, 0, 127 ); - db[1].draw.isbg = 1; - db[1].draw.dtd = 1; - - - /* Apply the drawing environment of the first double buffer */ - PutDrawEnv( &db[0].draw ); - - - /* Clear both ordering tables to make sure they are clean at the start */ - ClearOTagR( db[0].ot, OT_LEN ); - ClearOTagR( db[1].ot, OT_LEN ); - - /* Set primitive pointer address */ - db_nextpri = db[0].p; - - /* Initialize the GTE */ - InitGeom(); - - /* Set GTE offset (recommended method of centering) */ - gte_SetGeomOffset( CENTERX, CENTERY ); - - /* Set screen depth (basically FOV control, W/2 works best) */ - gte_SetGeomScreen( CENTERX ); - - GetTimInfo(tim_image, &tim); - - LoadImage(tim.prect, tim.paddr); - DrawSync(0); - - LoadImage(tim.crect, tim.caddr); - DrawSync(0); - -} - -void display() { - - /* Wait for GPU to finish drawing and vertical retrace */ - DrawSync( 0 ); - VSync( 0 ); - - /* Swap buffers */ - db_active ^= 1; - db_nextpri = db[db_active].p; - - /* Clear the OT of the next frame */ - ClearOTagR( db[db_active].ot, OT_LEN ); - - /* Apply display/drawing environments */ - PutDrawEnv( &db[db_active].draw ); - PutDispEnv( &db[db_active].disp ); - - /* Enable display */ - SetDispMask( 1 ); - - /* Start drawing the OT of the last buffer */ - DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); - -} \ No newline at end of file diff --git a/examples/billboard/makefile b/examples/billboard/makefile deleted file mode 100644 index 4c22b0c..0000000 --- a/examples/billboard/makefile +++ /dev/null @@ -1,39 +0,0 @@ -include ../sdk-common.mk - -TARGET = billboard.elf - -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) - -INCLUDE += -LIBDIRS += - -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc - -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x - -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -AS = $(PREFIX)as -LD = $(PREFIX)ld - -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/billboard/texture64.tim b/examples/billboard/texture64.tim deleted file mode 100644 index d3aff3a..0000000 Binary files a/examples/billboard/texture64.tim and /dev/null differ diff --git a/examples/billboard/tim.s b/examples/billboard/tim.s deleted file mode 100644 index 1fa8d69..0000000 --- a/examples/billboard/tim.s +++ /dev/null @@ -1,7 +0,0 @@ -.section .data - -.global tim_image -.type tim_image, @object -tim_image: - .incbin "texture64.tim" - \ No newline at end of file diff --git a/examples/cartrom/bios.inc b/examples/cartrom/bios.inc deleted file mode 100644 index 1c0201d..0000000 --- a/examples/cartrom/bios.inc +++ /dev/null @@ -1,67 +0,0 @@ -printf: - addiu $t2, $0, 0xA0 - jr $t2 - addiu $t1, $0, 0x3F - -atoi: - addiu $t2, $0, 0xA0 - jr $t2 - addiu $t1, $0, 0x10 - -toupper: - addiu $t2, $0, 0xA0 - jr $t2 - addiu $t1, $0, 0x25 - -open: - addiu $t2, $0, 0xB0 - jr $t2 - addiu $t1, $0, 0x32 - -read: - addiu $t2, $0, 0xB0 - jr $t2 - addiu $t1, $0, 0x34 - -close: - addiu $t2, $0, 0xB0 - jr $t2 - addiu $t1, $0, 0x36 - -_96_init: - addiu $t2, $0, 0xA0 - jr $t2 - addiu $t1, $0, 0x71 - -LoadExe: - addiu $t2, $0, 0xA0 - jr $t2 - addiu $t1, $0, 0x42 - -DoExec: - addiu $t2, $0, 0xA0 - jr $t2 - addiu $t1, $0, 0x43 - -SetConf: - addiu $t2, $0, 0xA0 - jr $t2 - addiu $t1, $0, 0x9C - -SetDefaultExitFromException: - addiu $t2, $0, 0xB0 - jr $t2 - addiu $t1, $0, 0x18 - -EnterCriticalSection: - addiu $a0, $0, 1 - syscall 0 - jr $ra - nop - -ExitCriticalSection: - addiu $a0, $0, 2 - syscall 0 - jr $ra - nop - \ No newline at end of file diff --git a/examples/cartrom/cop0.inc b/examples/cartrom/cop0.inc deleted file mode 100644 index 620fa44..0000000 --- a/examples/cartrom/cop0.inc +++ /dev/null @@ -1,11 +0,0 @@ -.set BPC, $3 -.set BDA, $5 -.set JUMPDEST, $6 -.set DCIC, $7 -.set BADVADDR, $8 -.set BDAM, $9 -.set BPCM, $11 -.set SR, $12 -.set CAUSE, $13 -.set EPC, $14 -.set PRID, $15 diff --git a/examples/cartrom/makefile b/examples/cartrom/makefile deleted file mode 100644 index 2434685..0000000 --- a/examples/cartrom/makefile +++ /dev/null @@ -1,14 +0,0 @@ -PREFIX = mipsel-unknown-elf- - -CC = $(PREFIX)gcc -AS = $(PREFIX)as -LD = $(PREFIX)ld - -all: rom.o - $(LD) --oformat binary -T rom.ld -o cartrom.rom rom.o - -%.o: %.s - $(AS) -msoft-float --warn $< -o $@ - -clean: - rm -f rom.o cartrom.rom \ No newline at end of file diff --git a/examples/cartrom/parse.inc b/examples/cartrom/parse.inc deleted file mode 100644 index b1190f7..0000000 --- a/examples/cartrom/parse.inc +++ /dev/null @@ -1,113 +0,0 @@ -# Skips spaces and equal signs (used by CNF parser) -skipspace: - # a0 - Input string - # Return: v0 - Address to first non-space character. - lbu $v1, 0($a0) - nop - beq $v1, ' ', .skip - nop - beq $v1, '=', .skip - nop - jr $ra - move $v0, $a0 -.skip: - b skipspace - addiu $a0, 1 - - -# Copies a string until a CR/LF or space is encountered -getline: - # a0 - Output address - # a1 - String to copy from - lbu $v0, 0($a1) - addiu $a1, 1 - beqz $v0, .end - nop - beq $v0, 0x0D, .end - nop - beq $v0, 0x0A, .end - nop - beq $v0, ' ', .end - nop - sb $v0, 0($a0) - b getline - addiu $a0, 1 -.end: - jr $ra - sb $0, 0($a0) - - -# strcasestr implementation -strcasestr: - # a0 - String to search - # a1 - String to find - addiu $sp, -24 - sw $ra, 0($sp) - sw $s0, 4($sp) - sw $s1, 8($sp) - sw $a1, 16($sp) - -.scan_start: - - sw $a0, 12($sp) - -.comp_loop: - - lbu $s0, 0($a0) # Load character from A and B - lbu $s1, 0($a1) - - beqz $s0, .end_strcasestr - nop - beqz $s1, .found - nop - - sw $a0, 20($sp) # Save a0 parameter - - jal toupper # tolower character A - move $a0, $s0 - move $s0, $v0 - - jal toupper # tolower character B - move $a0, $s1 - move $s1, $v0 - - lw $a0, 20($sp) # Restore a0 parameter - - addiu $a1, 1 - addiu $a0, 1 - - beq $s0, $s1, .comp_loop # If value matches continue compare - nop - -.end_strcasestr: - - lw $a0, 12($sp) # Rescan from next character of string A - lw $a1, 16($sp) - addiu $a0, 1 - - lbu $v0, 0($a0) - nop - beqz $v0, .not_found # If terminator is reached, string is not found - nop - - b .scan_start - nop - -.not_found: - - b .quit - move $v0, $0 - -.found: - - lw $v0, 12($sp) # Return address of string match - -.quit: - - lw $ra, 0($sp) - lw $s0, 4($sp) - lw $s1, 8($sp) - jr $ra - addiu $sp, 24 - - diff --git a/examples/cartrom/readme.txt b/examples/cartrom/readme.txt deleted file mode 100644 index 8d11a7f..0000000 --- a/examples/cartrom/readme.txt +++ /dev/null @@ -1,74 +0,0 @@ -LibPSn00b Example Programs -Part of the PSn00bSDK Poject - -TurboBoot Example by Lameguy64 - - -Explanation: - -This example demonstrates how to create a ROM program to be used on a cheat -cartridge such as an Action Replay or Xplorer using GNU assembler. The program -stored in ROM is executed pretty much instantly on power-on. - -The PS1 BIOS can execute code from a ROM chip connected to the expansion port -(or Parallel I/O port) such as a cheat cartridge provided the valid headers -are present. However, the boot vectors are somewhat limited as it only -provides a preboot vector and a postboot vector. - -The preboot vector is executed at the earliest point of the BIOS start-up -sequence which means the RAM is almost completely blank and you can't execute -PS-EXEs from this point whearas the postboot vector is only executed between -the PS logo and game execution. To get around this limitation, the preboot -vector is used to execute code that places a breakpoint to a desired point -in memory and returns execution to the BIOS. This will effectively intercept -execution once it reaches the breakpoint allowing to run code from ROM with -an initialized kernel allowing for bootstrapping PS-EXEs from ROM, CD or -from a comms interface such as serial. - -The Xplorer and later Pro Action Replay cheat devices use this so called -'midboot' trick in their firmwares. - -In this TurboBoot example, the ROM program attempts to boot a PS-EXE from -CD using BIOS CD-ROM and file functions. It will also parse through the -SYSTEM.CNF to retrieve the file name of executable as well as some boot -parameters such as stack addres and number of TCBs and EvCBs. The ROM -program can fallback to attempting to load a PS-EXE named PSX.EXE if the -SYSTEM.CNF file does not exist like in the official BIOS. - -This example can also be used as a turbo boot utility as it boots straight -to the game, skipping the start-up animation altogether. It cannot be used -as a way to bypass the authentication check of an unmodified console however -(though it would help with bypassing the license data check on older Japanese -consoles) as the CD-ROM would only read data discs correctly IF the elusive -wobble groove containing the SCE string of the disc is present or when a -modchip is installed. It is possible to circumvent this by issuing special -'CD Unlock' commands (see nocash's psx-spx document) to the CD-ROM controller -which would effectively turn this into a chipless modchip solution that plugs -to the expansion port. However, the unlock commands only works on US and EU -consoles. - -It is possible and pretty trivial to boot a PS-EXE straight from ROM by -simply copying the program text from ROM to its desired location in RAM and -transferring execution to it. Such an example may be created in the future. - -This ROM program example had to be written entirely in assembly as C cannot -be used to write a ROM program even though it should be possible with some -assembly code to take care of the bootstrapping. GNU ld would complain about -'relocation truncation of R_MIPS_GPREL16' when you map program text to ROM -starting at 0x1f000000 (EXP ROM segment) and program data and bss sections -to RAM. Unknown how to get around this as all methods I've tried so far -either don't work or it just produces a massive binary file. - - -Building: - -To build this example, simply run make and a file named cartrom.rom should -be created. Run the ROM in no$psx (make sure a ISO image has been opened -first) or burn it to an Xplorer/PAR EEPROM (I recommend modding a PAR with -a DIP32 socket if you wish to program the chip externally which in many -cases would be easier). - - -Changelog: - -May 23, 2019 - Initial version. diff --git a/examples/cartrom/rom.ld b/examples/cartrom/rom.ld deleted file mode 100644 index f3f9cd3..0000000 --- a/examples/cartrom/rom.ld +++ /dev/null @@ -1,11 +0,0 @@ -MEMORY { - ROM : ORIGIN = 0x1f000000, LENGTH = 256K -} - -ENTRY (entry) - -SECTIONS { - .text :{ - *(.text) - } >ROM -} diff --git a/examples/cartrom/rom.s b/examples/cartrom/rom.s deleted file mode 100644 index 14c1167..0000000 --- a/examples/cartrom/rom.s +++ /dev/null @@ -1,399 +0,0 @@ -# LibPSn00b Example Programs -# Part of the PSn00bSDk project -# -# TurboBoot Example by Lameguy64 -# - - -# Uncomment either PAR or XPLORER depending on the cartridge -# you're going to use (makes disabling turbo boot via switch to work) - -#.set PAR, 0 -#.set XPLORER, 1 - - -.set noreorder - -.include "cop0.inc" # Contains definitions for cop0 registers - -.set SP_base, 0x801ffff0 -.set BREAK_ADDR, 0xa0000040 # cop0 breakpoint vector address - - -.set RAM_buff, 2048 -.set RAM_handle, 2052 -.set RAM_tcb, 2056 -.set RAM_evcb, 2060 -.set RAM_stack, 2064 -.set RAM_psexe, 2068 - - -.set EXE_pc0, 0 # PS-EXE header offsets -.set EXE_gp0, 4 -.set EXE_taddr, 8 -.set EXE_tsize, 12 -.set EXE_daddr, 16 -.set EXE_dsize, 20 -.set EXE_baddr, 24 -.set EXE_bsize, 28 -.set EXE_spaddr, 32 -.set EXE_sp_size, 36 -.set EXE_sp, 40 -.set EXE_fp, 44 -.set EXE_gp, 48 -.set EXE_ret, 52 -.set EXE_base, 56 -.set EXE_datapos, 60 - - -.section .text - - -# ROM header -# -# The Licensed by... strings are essential otherwise the BIOS will not -# execute the boot vectors. Always make sure the tty message fields (string -# after Licensed by) must be no more than 80 bytes long and must have a null -# terminating byte. -# -# Postboot vector isn't particularly practical as its only executed in between -# the PS boot logo and the point where game execution occurs. -# -header: - # Postboot vector - .word 0 - .ascii "Licensed by Sony Computer Entertainment Inc." - .ascii "Not officially licensed or endorsed by Sony Computer Entertainment Inc." - - .balign 0x80 # This keeps things in the header aligned - - # Preboot vector - .word preboot - .ascii "Licensed by Sony Computer Entertainment Inc." - .ascii "Cart ROM example for PSn00bSDK https://github.com/lameguy64/psn00bsdk" - - .balign 0x80 # This keeps things in the header aligned - - -# Preboot vector -# -# All it does is it initializes a breakpoint vector at 0x40 -# and sets a cop0 breakpoint at 0x80030000 to perform a midboot -# exploit as preboot doesn't have the kernel area initialized. -# -preboot: - - li $v0, 1 - -.ifdef XPLORER - lui $a0, 0x1f06 # Read switch status for Xplorer - lbu $v0, 0($a0) -.endif - -.ifdef PAR - lui $a0, 0x1f02 # Read switch status for PAR/GS devices - lbu $v0, 0x18($a0) -.endif - - nop - andi $v0, 0x1 - beqz $v0, .no_rom # If switch is off don't install hook - nop # and effectively disables the cartridge - - li $v0, BREAK_ADDR # Patch a jump at cop0 breakpoint vector - - li $a0, 0x3c1a1f00 # lui $k0, $1f00 - sw $a0, 0($v0) - la $a1, entry # ori $k0, < address to code entrypoint > - andi $a1, 0xffff - lui $a0, 0x375a - or $a0, $a1 - sw $a0, 4($v0) - li $a0, 0x03400008 # jr $k0 - sw $a0, 8($v0) - sw $0 , 12($v0) # nop - - lui $v0, 0xffff # Set BPCM and BDAM masks - ori $v0, 0xffff - mtc0 $v0, BDAM - mtc0 $v0, BPCM - - - li $v0, 0x80030000 # Set break on PC and data-write address - - mtc0 $v0, BDA # BPC break is for compatibility with no$psx - mtc0 $v0, BPC # as it does not emulate break on BDA - - lui $v0, 0xeb80 # Enable break on data-write and and break - mtc0 $v0, DCIC # on PC to DCIC control register - -.no_rom: - - jr $ra # Return to BIOS - nop - - -# Actual ROM entrypoint -.global entry -entry: - - mtc0 $0 , DCIC # Clear DCIC register - - la $sp, SP_base # Set stack base - la $gp, 0x8000c000 # Set GP address as RAM base addr in this case - - jal SetDefaultExitFromException # Set default exit handler just in case - nop - jal ExitCriticalSection # Exit out of critical section (brings back interrupts) - nop - - # Beyond this point, the PS1 is in full control to the ROM - - la $a0, m_banner # Print out program banner - jal printf - addiu $sp, -4 - addiu $sp, 4 - - la $a0, m_cdinit - jal printf - addiu $sp, -4 - addiu $sp, 4 - - jal _96_init # Initialize the CD - nop - - la $a0, m_ok # Print OK message if init didn't crash - jal printf - addiu $sp, -4 - addiu $sp, 4 - - la $a0, m_readfile - la $a1, s_systemcnf - jal printf - addiu $sp, -8 - addiu $sp, 8 - - la $a0, s_systemcnf # Attempt to open the SYSTEM.CNF file on CD - li $a1, 1 - jal open - addiu $sp, -8 - addiu $sp, 8 - - bltz $v0, .no_systemcnf # Fallback to loading PSX.EXE if not found - nop - - sw $v0, RAM_handle($gp) # Save file handle - - move $a0, $v0 # Read file contents of SYSTEM.CNF - move $a1, $gp - li $a2, 0x0800 - jal read - addiu $sp, -12 - addiu $sp, 12 - - lw $a0, RAM_handle($gp) # Close file - jal close - addiu $sp, -4 - addiu $sp, 4 - - la $a0, m_ok # Output ok message - jal printf - addiu $sp, -4 - addiu $sp, 4 - - # Parse CNF file - - la $a0, m_parsecnf - jal printf - nop - - la $a1, s_tcb # Get TCB number - jal strcasestr - move $a0, $gp - jal skipspace # Skip spaces - addiu $a0, $v0, 3 - addiu $a0, $v0, -2 # Step two charactters back and inject '0x' - li $v0, '0' - sb $v0, 0($a0) - li $v0, 'x' - sb $v0, 1($a0) - jal atoi - addiu $sp, -4 - addiu $sp, 4 - move $s1, $v0 - - la $a1, s_evcb # Get EVCB number - jal strcasestr - move $a0, $gp - jal skipspace - addiu $a0, $v0, 5 - addiu $a0, $v0, -2 - li $v0, '0' - sb $v0, 0($a0) - li $v0, 'x' - sb $v0, 1($a0) - jal atoi - addiu $sp, -4 - addiu $sp, 4 - move $s0, $v0 - - la $a1, s_stack # Get STACK address - jal strcasestr - move $a0, $gp - jal skipspace - addiu $a0, $v0, 5 - addiu $a0, $v0, -2 - li $v0, '0' - sb $v0, 0($a0) - li $v0, 'x' - sb $v0, 1($a0) - jal atoi - addiu $sp, -4 - addiu $sp, 4 - move $s2, $v0 - - la $a1, s_boot # Get the PS-EXE file name - jal strcasestr - move $a0, $gp - - jal skipspace # Skip spaces - addiu $a0, $v0, 4 - - addiu $a0, $gp, RAM_psexe # Extract the line - jal getline - move $a1, $v0 - - la $a0, m_ok # Print successful parsing - jal printf - addiu $sp, -4 - addiu $sp, 4 - - la $a0, m_readfile - addiu $a1, $gp, RAM_psexe - jal printf - addiu $sp, -8 - addiu $sp, 8 - - b .do_load # Proceed loading PS-EXE - addiu $a0, $gp, RAM_psexe - -.no_systemcnf: # Load fallback - - la $a0, m_notfound - jal printf - addiu $sp, -4 - addiu $sp, 4 - - la $a0, m_fallback - jal printf - addiu $sp, -4 - addiu $sp, 4 - - li $s0, 0x10 # Default EvCBs and TCBs - li $s1, 0x04 - li $s2, SP_base # Default stack - la $a0, s_psxexe # Attempt loading PSX.EXE - -.do_load: - - jal LoadExe # Load PS-EXE - move $a1, $gp - - beqz $v0, load_fail - nop - - la $a0, m_ok - jal printf - addiu $sp, -4 - addiu $sp, 4 - - sw $s2, EXE_sp($gp) # Patch the header - sw $s2, EXE_spaddr($gp) - - la $a0, m_boot - jal printf - addiu $sp, -4 - addiu $sp, 4 - - jal EnterCriticalSection # Disable interrupt handling - nop - - move $a0, $s0 # Set configuration (EvCBs and TCBs) - move $a1, $s1 - move $a2, $s2 - jal SetConf - addiu $sp, -12 - addiu $sp, 12 - - move $a0, $gp # Transfer execution - move $a1, $0 - move $a2, $0 - jal DoExec - addiu $sp, -12 - addiu $sp, 12 - - -load_fail: # Fail state - la $a0, m_loadfail - jal printf - nop -.fail_loop: - b .fail_loop - nop - - -.include "parse.inc" -.include "bios.inc" - - -# Strings - -s_boot: - .asciz "BOOT" - .balign 4 -s_tcb: - .asciz "TCB" - .balign 4 -s_evcb: - .asciz "EVENT" - .balign 4 -s_stack: - .asciz "STACK" - .balign 4 -s_systemcnf: - .asciz "cdrom:SYSTEM.CNF;1" - .balign 4 -s_psxexe: - .asciz "cdrom:PSX.EXE;1" - .balign 4 - - -# Message strings - -m_banner: - .asciz "\nCARTROM Bootstrap Example by Lameguy64\nPart of the PSn00bSDK Project\n\n" - .balign 4 -m_cdinit: - .asciz "Initializing CD-ROM (BIOS)... " - .balign 4 -m_readfile: - .asciz "Attempting to read %s... " - .balign 4 -m_parsecnf: - .asciz "Parsing CNF file... " - .balign 4 -m_fallback: - .asciz "Falling back to loading PSX.EXE... " - .balign 4 -m_notfound: - .asciiz "Not found.\n" - .balign 4 -m_ok: - .asciz "Ok.\n" - .balign 4 -m_boot: - .asciz "Boot!\n" - .balign 4 -m_loadfail: - .asciz "Failed to load PS-EXE file.\n" - .balign 4 diff --git a/examples/cdbrowse/ball16c.h b/examples/cdbrowse/ball16c.h deleted file mode 100644 index c79f273..0000000 --- a/examples/cdbrowse/ball16c.h +++ /dev/null @@ -1,16 +0,0 @@ -unsigned int ball16c_size=192; -unsigned char ball16c[] = { -0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, -0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, -0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, -0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, -0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, -0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, -0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, -0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, -0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, -0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, -0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, -0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, -0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 -}; diff --git a/examples/cdbrowse/iso.xml b/examples/cdbrowse/iso.xml deleted file mode 100644 index a828df1..0000000 --- a/examples/cdbrowse/iso.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/cdbrowse/main.c b/examples/cdbrowse/main.c deleted file mode 100644 index 65475ad..0000000 --- a/examples/cdbrowse/main.c +++ /dev/null @@ -1,517 +0,0 @@ -/* - * LibPSn00b Example Programs - * - * CD File Browser Example - * 2020 Meido-Tek Productions / PSn00bSDK Project - * - * Demonstrates listing and browsing directory contents of a CD-ROM containing - * an ISO9660 file system, using the directory query functions of the libpsxcd - * library. - * - * The ISO9660 support in libpsxcd only supports the original ISO9660 - * version 1 file system specification, meaning it cannot query Rock Ridge - * or Joliet extensions that allow for long file names and unicode, despite - * the ISO9660 version 1 specification supporting names longer than 8.3 to - * begin with. However, discs written with such extensions should still be - * readable as the ISO9660 version should still be present for compatibility, - * with file names truncated to 8.3. - * - * - * Directory querying with libpsxcd is accomplished by using functions - * CdOpenDir(), CdReadDir() and CdCloseDir(). These functions work more or - * less the same as opendir(), readdir() and closedir() in *nix-like - * environments. While the library can support directories containing - * any number of files, the file browser in this example is limited to 40 - * entries, but this can be easily extended if need be. - * - * Differentiating file and directory entries is easily determined by whether - * or not the file has a version number suffix (ie. MYFILE.DAT;1). Directory - * records do not have a version number suffix. - * - * Currently, the only way to signal the isofs routines of libpsxcd that a - * disc change has occured is by simply issuing a CdlNop command. In a file - * browser that is aware of a disc change occuring at any moment a CdlNop - * command shall be issued at regular intervals of at least once a second. - * This also keeps CdStatus() up to date with disc presence. - * - * - * Controls: - * - * Up/Down - Move selection cursor. - * Cross - Enter directory. - * Circle - Go back to root directory. - * - * - * Example by Lameguy64 - * - * - * Changelog: - * - * February 25, 2020: Initial version. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "ball16c.h" - - -#define MAX_BALLS 1536 /* Number of balls to display */ - -#define OT_LEN 8 /* Ordering table length */ - - -/* Screen coordinates */ -#define SCREEN_XRES 320 -#define SCREEN_YRES 240 - -#define CENTER_X SCREEN_XRES/2 -#define CENTER_Y SCREEN_YRES/2 - - -/* Display and drawing environments */ -DISPENV disp[2]; -DRAWENV draw[2]; - -char pribuff[2][65536]; /* Primitive packet buffers */ -unsigned int ot[2][OT_LEN]; /* Ordering tables */ -char *nextpri; /* Pointer to next packet buffer offset */ -int db = 0; /* Double buffer index */ - - -/* Ball struct and array */ -typedef struct BALL_TYPE -{ - short x,y; - short xdir,ydir; - unsigned char r,g,b,p; -} BALL_TYPE; - -BALL_TYPE balls[MAX_BALLS]; - - -/* TIM image parameters for loading the ball texture and drawing sprites */ -TIM_IMAGE tim; - -/* Pad input buffer*/ -char padbuff[2][34]; - - -int query_dir(const char* path, CdlFILE* files, int max) -{ - CdlDIR* dir; - int files_found; - - printf( "Querying directory %s... ", path ); - files_found = 0; - - /* Open the directory */ - dir = CdOpenDir( path ); - if( dir ) - { - /* Read entries */ - while( CdReadDir( dir, &files[files_found] ) ) - { - files_found++; - if( files_found >= max ) - break; - } - - /* Close directory after query */ - CdCloseDir( dir ); - } - else - { - /* If directory path does not exist */ - printf( "Directory not found.\n" ); - return 0; - } - - printf( "Done.\n" ); - return files_found; -} - - -void init() -{ - int i; - - /* Reset GPU (also installs event handler for VSync) */ - printf("Init GPU... "); - ResetGraph( 0 ); - printf("Done.\n"); - - - /* Uncomment to direct tty messages to serial */ - //AddSIO(115200); - - - /* Initialize SPU and CD-ROM */ - printf("Initializing CD-ROM... "); - SpuInit(); - CdInit(); - printf("Done.\n"); - - - /* Set display and draw environment parameters */ - SetDefDispEnv(&disp[0], 0, 0, SCREEN_XRES, SCREEN_YRES); - SetDefDispEnv(&disp[1], 0, SCREEN_YRES, SCREEN_XRES, SCREEN_YRES); - - SetDefDrawEnv(&draw[0], 0, SCREEN_YRES, SCREEN_XRES, SCREEN_YRES); - SetDefDrawEnv(&draw[1], 0, 0, SCREEN_XRES, SCREEN_YRES); - - - /* Set clear color, area clear and dither processing */ - setRGB0(&draw[0], 63, 0, 127); - draw[0].isbg = 1; - draw[0].dtd = 1; - setRGB0(&draw[1], 63, 0, 127); - draw[1].isbg = 1; - draw[1].dtd = 1; - - - /* Load and open font stream */ - FntLoad(960, 0); - FntOpen(32, 32, 256, 176, 2, 400); - - - /* Upload the ball texture */ - GetTimInfo((unsigned int*)ball16c, &tim); /* Get TIM parameters */ - LoadImage(tim.prect, tim.paddr); /* Upload texture to VRAM */ - if( tim.mode & 0x8 ) - { - LoadImage(tim.crect, tim.caddr); /* Upload CLUT if present */ - } - - - /* Calculate ball positions */ - printf("Calculating balls... "); - - for(i=0; istat == 0 ) - { - if(( pad->type == 0x4 )||( pad->type == 0x5 )||( pad->type == 0x7 )) - { - /* Menu controls */ - if( disc_present ) - { - if( !(pad->btn&PAD_UP) ) - { - if( !p_up ) - { - if( sel_channel > 0 ) - { - sel_channel--; - - if( (sel_channel-list_scroll) < 0 ) - { - list_scroll = sel_channel; - } - } - p_up = 1; - } - } - else - { - p_up = 0; - } - - if( !(pad->btn&PAD_DOWN) ) - { - if( !p_down ) - { - if( sel_channel < files_found-1 ) - { - sel_channel++; - - if( (sel_channel-list_scroll) > 15 ) - { - list_scroll = sel_channel-15; - } - } - p_down = 1; - } - } - else - { - p_down = 0; - } - } - - /* Enter a selected directory */ - if( !(pad->btn&PAD_CROSS) ) - { - if( !p_cross ) - { - if( disc_present ) - { - if( strchr( files[sel_channel].name, ';' ) == 0 ) - { - if( strcmp( files[sel_channel].name, ".." ) - == 0 ) - { - *(strrchr( path, '\\' )+1) = 0x0; - if( strlen( path ) > 1 ) - { - path[strlen( path )-1] = 0x0; - } - } - else if( strcmp( files[sel_channel].name, "." ) ) - { - if( strlen( path ) > 1 ) - { - strcat( path, "\\" ); - } - strcat( path, files[sel_channel].name ); - } - update_listing = true; - } - } - else - { - strcpy( path, "\\" ); - update_listing = true; - } - p_cross = 1; - } - } - else - { - p_cross = 0; - } - - /* Return to root directory */ - if( !(pad->btn&PAD_CIRCLE) ) - { - if( !p_circle ) - { - strcpy( path, "\\" ); - update_listing = true; - p_circle = 1; - } - } - else - { - p_circle = 0; - } - } - } - - - /* Updates directory listing */ - if( update_listing ) - { - if ( (CdStatus()&0x12) == 0x2 ) - { - - /* Reset path and update label if new disc inserted */ - if( !disc_present ) - { - strcpy( path, "\\" ); - CdGetVolumeLabel(disc_label); - disc_present = true; - } - - /* Query directory */ - files_found = query_dir( path, files, 40 ); - sel_channel = 0; - list_scroll = 0; - - } - update_listing = false; - } - - - /* Display information */ - FntPrint( -1, "\n PSN00BSDK CD BROWSER EXAMPLE\n\n" ); - - if( disc_present ) - { - FntPrint( -1, " FILES:%d LABEL:%s\n", files_found, disc_label ); - FntPrint( -1, " %s\n", path ); - - for(i=0; i<16; i++) - { - if( (i+list_scroll) > (files_found-1) ) - break; - - if( (i+list_scroll) == sel_channel ) - { - FntPrint( -1, " ->%s\n", files[i+list_scroll].name ); - } - else - { - FntPrint( -1, " %s\n", files[i+list_scroll].name ); - } - - } - } - else - { - if( (CdStatus()&0x12) == 0x2 ) - { - FntPrint( -1, "\n PRESS TO LIST CONTENTS %x\n", - CdStatus() ); - } - else - { - FntPrint( -1, "\n NO DISC INSERTED %x\n", - CdStatus() ); - } - } - - /* Clear ordering table and set start address of primitive buffer */ - ClearOTagR(ot[db], OT_LEN); - nextpri = pribuff[db]; - - - /* Sort the balls */ - sprt = (SPRT_16*)nextpri; - for( i=0; ix, tim.crect->y); - - addPrim(ot[db]+(OT_LEN-1), sprt); - sprt++; - - balls[i].x += balls[i].xdir; - balls[i].y += balls[i].ydir; - - if( ( balls[i].x+16 ) > SCREEN_XRES ) { - balls[i].xdir = -2; - } else if( balls[i].x < 0 ) { - balls[i].xdir = 2; - } - - if( ( balls[i].y+16 ) > SCREEN_YRES ) { - balls[i].ydir = -2; - } else if( balls[i].y < 0 ) { - balls[i].ydir = 2; - } - - } - nextpri = (char*)sprt; - - - /* Sort a TPage primitive so the sprites will draw pixels from */ - /* the correct texture page in VRAM */ - tpri = (DR_TPAGE*)nextpri; - setDrawTPage(tpri, 0, 0, getTPage(0, 0, tim.prect->x, tim.prect->y)); - addPrim(ot[db]+(OT_LEN-1), tpri); - nextpri += sizeof(DR_TPAGE); - - /* Draw font */ - FntFlush(-1); - - /* Wait for GPU and VSync */ - DrawSync(0); - VSync(0); - - /* Since draw.isbg is non-zero this clears the screen */ - PutDispEnv(&disp[db]); - PutDrawEnv(&draw[db]); - SetDispMask(1); - - /* Begin drawing the new frame */ - DrawOTag( ot[db]+(OT_LEN-1) ); - - /* Alternate to the next buffer */ - db = !db; - - /* Periodically issue a CdlNop to keep CdStatus() updated */ - counter++; - if( (counter%60) == 59 ) - { - CdControl(CdlNop, 0, 0); - } - } - - return 0; - -} diff --git a/examples/cdbrowse/makefile b/examples/cdbrowse/makefile deleted file mode 100644 index 7e90b3c..0000000 --- a/examples/cdbrowse/makefile +++ /dev/null @@ -1,59 +0,0 @@ -include ../sdk-common.mk - -TARGET = cdbrowse.elf - -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) - -PREFIX = mipsel-unknown-elf- - -# Include directories -INCLUDE = -I../../libpsn00b/include - -# Library directories, last entry must point toolchain libraries -LIBDIRS = -L../../libpsn00b - -LIBDIRS += -L$(GCC_BASE)/lib/gcc/mipsel-unknown-elf/$(GCC_VERSION) -INCLUDE += -I$(GCC_BASE)/lib/gcc/mipsel-unknown-elf/$(GCC_VERSION)/include - -LIBS = -lpsxcd -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxsio -lpsxapi -lc - -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) \ - -fno-exceptions \ - -fno-rtti \ - -fno-unwind-tables \ - -fno-threadsafe-statics \ - -fno-use-cxa-atexit - -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x - -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -AS = $(PREFIX)as -LD = $(PREFIX)ld - -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - mkpsxiso -y -q iso.xml - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/cdbrowse/system.cnf b/examples/cdbrowse/system.cnf deleted file mode 100644 index 9cf5593..0000000 --- a/examples/cdbrowse/system.cnf +++ /dev/null @@ -1,4 +0,0 @@ -BOOT=cdrom:\cdbrowse.exe;1 -TCB=4 -EVENT=10 -STACK=801FFFF0 diff --git a/examples/cdrom/cdbrowse/ball16c.h b/examples/cdrom/cdbrowse/ball16c.h new file mode 100644 index 0000000..c79f273 --- /dev/null +++ b/examples/cdrom/cdbrowse/ball16c.h @@ -0,0 +1,16 @@ +unsigned int ball16c_size=192; +unsigned char ball16c[] = { +0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, +0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, +0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, +0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, +0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, +0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, +0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, +0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, +0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, +0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, +0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, +0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, +0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 +}; diff --git a/examples/cdrom/cdbrowse/iso.xml b/examples/cdrom/cdbrowse/iso.xml new file mode 100644 index 0000000..a828df1 --- /dev/null +++ b/examples/cdrom/cdbrowse/iso.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/cdrom/cdbrowse/main.c b/examples/cdrom/cdbrowse/main.c new file mode 100644 index 0000000..65475ad --- /dev/null +++ b/examples/cdrom/cdbrowse/main.c @@ -0,0 +1,517 @@ +/* + * LibPSn00b Example Programs + * + * CD File Browser Example + * 2020 Meido-Tek Productions / PSn00bSDK Project + * + * Demonstrates listing and browsing directory contents of a CD-ROM containing + * an ISO9660 file system, using the directory query functions of the libpsxcd + * library. + * + * The ISO9660 support in libpsxcd only supports the original ISO9660 + * version 1 file system specification, meaning it cannot query Rock Ridge + * or Joliet extensions that allow for long file names and unicode, despite + * the ISO9660 version 1 specification supporting names longer than 8.3 to + * begin with. However, discs written with such extensions should still be + * readable as the ISO9660 version should still be present for compatibility, + * with file names truncated to 8.3. + * + * + * Directory querying with libpsxcd is accomplished by using functions + * CdOpenDir(), CdReadDir() and CdCloseDir(). These functions work more or + * less the same as opendir(), readdir() and closedir() in *nix-like + * environments. While the library can support directories containing + * any number of files, the file browser in this example is limited to 40 + * entries, but this can be easily extended if need be. + * + * Differentiating file and directory entries is easily determined by whether + * or not the file has a version number suffix (ie. MYFILE.DAT;1). Directory + * records do not have a version number suffix. + * + * Currently, the only way to signal the isofs routines of libpsxcd that a + * disc change has occured is by simply issuing a CdlNop command. In a file + * browser that is aware of a disc change occuring at any moment a CdlNop + * command shall be issued at regular intervals of at least once a second. + * This also keeps CdStatus() up to date with disc presence. + * + * + * Controls: + * + * Up/Down - Move selection cursor. + * Cross - Enter directory. + * Circle - Go back to root directory. + * + * + * Example by Lameguy64 + * + * + * Changelog: + * + * February 25, 2020: Initial version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "ball16c.h" + + +#define MAX_BALLS 1536 /* Number of balls to display */ + +#define OT_LEN 8 /* Ordering table length */ + + +/* Screen coordinates */ +#define SCREEN_XRES 320 +#define SCREEN_YRES 240 + +#define CENTER_X SCREEN_XRES/2 +#define CENTER_Y SCREEN_YRES/2 + + +/* Display and drawing environments */ +DISPENV disp[2]; +DRAWENV draw[2]; + +char pribuff[2][65536]; /* Primitive packet buffers */ +unsigned int ot[2][OT_LEN]; /* Ordering tables */ +char *nextpri; /* Pointer to next packet buffer offset */ +int db = 0; /* Double buffer index */ + + +/* Ball struct and array */ +typedef struct BALL_TYPE +{ + short x,y; + short xdir,ydir; + unsigned char r,g,b,p; +} BALL_TYPE; + +BALL_TYPE balls[MAX_BALLS]; + + +/* TIM image parameters for loading the ball texture and drawing sprites */ +TIM_IMAGE tim; + +/* Pad input buffer*/ +char padbuff[2][34]; + + +int query_dir(const char* path, CdlFILE* files, int max) +{ + CdlDIR* dir; + int files_found; + + printf( "Querying directory %s... ", path ); + files_found = 0; + + /* Open the directory */ + dir = CdOpenDir( path ); + if( dir ) + { + /* Read entries */ + while( CdReadDir( dir, &files[files_found] ) ) + { + files_found++; + if( files_found >= max ) + break; + } + + /* Close directory after query */ + CdCloseDir( dir ); + } + else + { + /* If directory path does not exist */ + printf( "Directory not found.\n" ); + return 0; + } + + printf( "Done.\n" ); + return files_found; +} + + +void init() +{ + int i; + + /* Reset GPU (also installs event handler for VSync) */ + printf("Init GPU... "); + ResetGraph( 0 ); + printf("Done.\n"); + + + /* Uncomment to direct tty messages to serial */ + //AddSIO(115200); + + + /* Initialize SPU and CD-ROM */ + printf("Initializing CD-ROM... "); + SpuInit(); + CdInit(); + printf("Done.\n"); + + + /* Set display and draw environment parameters */ + SetDefDispEnv(&disp[0], 0, 0, SCREEN_XRES, SCREEN_YRES); + SetDefDispEnv(&disp[1], 0, SCREEN_YRES, SCREEN_XRES, SCREEN_YRES); + + SetDefDrawEnv(&draw[0], 0, SCREEN_YRES, SCREEN_XRES, SCREEN_YRES); + SetDefDrawEnv(&draw[1], 0, 0, SCREEN_XRES, SCREEN_YRES); + + + /* Set clear color, area clear and dither processing */ + setRGB0(&draw[0], 63, 0, 127); + draw[0].isbg = 1; + draw[0].dtd = 1; + setRGB0(&draw[1], 63, 0, 127); + draw[1].isbg = 1; + draw[1].dtd = 1; + + + /* Load and open font stream */ + FntLoad(960, 0); + FntOpen(32, 32, 256, 176, 2, 400); + + + /* Upload the ball texture */ + GetTimInfo((unsigned int*)ball16c, &tim); /* Get TIM parameters */ + LoadImage(tim.prect, tim.paddr); /* Upload texture to VRAM */ + if( tim.mode & 0x8 ) + { + LoadImage(tim.crect, tim.caddr); /* Upload CLUT if present */ + } + + + /* Calculate ball positions */ + printf("Calculating balls... "); + + for(i=0; istat == 0 ) + { + if(( pad->type == 0x4 )||( pad->type == 0x5 )||( pad->type == 0x7 )) + { + /* Menu controls */ + if( disc_present ) + { + if( !(pad->btn&PAD_UP) ) + { + if( !p_up ) + { + if( sel_channel > 0 ) + { + sel_channel--; + + if( (sel_channel-list_scroll) < 0 ) + { + list_scroll = sel_channel; + } + } + p_up = 1; + } + } + else + { + p_up = 0; + } + + if( !(pad->btn&PAD_DOWN) ) + { + if( !p_down ) + { + if( sel_channel < files_found-1 ) + { + sel_channel++; + + if( (sel_channel-list_scroll) > 15 ) + { + list_scroll = sel_channel-15; + } + } + p_down = 1; + } + } + else + { + p_down = 0; + } + } + + /* Enter a selected directory */ + if( !(pad->btn&PAD_CROSS) ) + { + if( !p_cross ) + { + if( disc_present ) + { + if( strchr( files[sel_channel].name, ';' ) == 0 ) + { + if( strcmp( files[sel_channel].name, ".." ) + == 0 ) + { + *(strrchr( path, '\\' )+1) = 0x0; + if( strlen( path ) > 1 ) + { + path[strlen( path )-1] = 0x0; + } + } + else if( strcmp( files[sel_channel].name, "." ) ) + { + if( strlen( path ) > 1 ) + { + strcat( path, "\\" ); + } + strcat( path, files[sel_channel].name ); + } + update_listing = true; + } + } + else + { + strcpy( path, "\\" ); + update_listing = true; + } + p_cross = 1; + } + } + else + { + p_cross = 0; + } + + /* Return to root directory */ + if( !(pad->btn&PAD_CIRCLE) ) + { + if( !p_circle ) + { + strcpy( path, "\\" ); + update_listing = true; + p_circle = 1; + } + } + else + { + p_circle = 0; + } + } + } + + + /* Updates directory listing */ + if( update_listing ) + { + if ( (CdStatus()&0x12) == 0x2 ) + { + + /* Reset path and update label if new disc inserted */ + if( !disc_present ) + { + strcpy( path, "\\" ); + CdGetVolumeLabel(disc_label); + disc_present = true; + } + + /* Query directory */ + files_found = query_dir( path, files, 40 ); + sel_channel = 0; + list_scroll = 0; + + } + update_listing = false; + } + + + /* Display information */ + FntPrint( -1, "\n PSN00BSDK CD BROWSER EXAMPLE\n\n" ); + + if( disc_present ) + { + FntPrint( -1, " FILES:%d LABEL:%s\n", files_found, disc_label ); + FntPrint( -1, " %s\n", path ); + + for(i=0; i<16; i++) + { + if( (i+list_scroll) > (files_found-1) ) + break; + + if( (i+list_scroll) == sel_channel ) + { + FntPrint( -1, " ->%s\n", files[i+list_scroll].name ); + } + else + { + FntPrint( -1, " %s\n", files[i+list_scroll].name ); + } + + } + } + else + { + if( (CdStatus()&0x12) == 0x2 ) + { + FntPrint( -1, "\n PRESS TO LIST CONTENTS %x\n", + CdStatus() ); + } + else + { + FntPrint( -1, "\n NO DISC INSERTED %x\n", + CdStatus() ); + } + } + + /* Clear ordering table and set start address of primitive buffer */ + ClearOTagR(ot[db], OT_LEN); + nextpri = pribuff[db]; + + + /* Sort the balls */ + sprt = (SPRT_16*)nextpri; + for( i=0; ix, tim.crect->y); + + addPrim(ot[db]+(OT_LEN-1), sprt); + sprt++; + + balls[i].x += balls[i].xdir; + balls[i].y += balls[i].ydir; + + if( ( balls[i].x+16 ) > SCREEN_XRES ) { + balls[i].xdir = -2; + } else if( balls[i].x < 0 ) { + balls[i].xdir = 2; + } + + if( ( balls[i].y+16 ) > SCREEN_YRES ) { + balls[i].ydir = -2; + } else if( balls[i].y < 0 ) { + balls[i].ydir = 2; + } + + } + nextpri = (char*)sprt; + + + /* Sort a TPage primitive so the sprites will draw pixels from */ + /* the correct texture page in VRAM */ + tpri = (DR_TPAGE*)nextpri; + setDrawTPage(tpri, 0, 0, getTPage(0, 0, tim.prect->x, tim.prect->y)); + addPrim(ot[db]+(OT_LEN-1), tpri); + nextpri += sizeof(DR_TPAGE); + + /* Draw font */ + FntFlush(-1); + + /* Wait for GPU and VSync */ + DrawSync(0); + VSync(0); + + /* Since draw.isbg is non-zero this clears the screen */ + PutDispEnv(&disp[db]); + PutDrawEnv(&draw[db]); + SetDispMask(1); + + /* Begin drawing the new frame */ + DrawOTag( ot[db]+(OT_LEN-1) ); + + /* Alternate to the next buffer */ + db = !db; + + /* Periodically issue a CdlNop to keep CdStatus() updated */ + counter++; + if( (counter%60) == 59 ) + { + CdControl(CdlNop, 0, 0); + } + } + + return 0; + +} diff --git a/examples/cdrom/cdbrowse/makefile b/examples/cdrom/cdbrowse/makefile new file mode 100644 index 0000000..f5ee962 --- /dev/null +++ b/examples/cdrom/cdbrowse/makefile @@ -0,0 +1,52 @@ +include ../../sdk-common.mk + +TARGET = cdbrowse.elf + +CFILES = $(notdir $(wildcard *.c)) +CPPFILES = $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) + +PREFIX = mipsel-unknown-elf- + +LIBS = -lpsxcd -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxsio -lpsxapi -lc + +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +CPPFLAGS = $(CFLAGS) \ + -fno-exceptions \ + -fno-rtti \ + -fno-unwind-tables \ + -fno-threadsafe-statics \ + -fno-use-cxa-atexit + +AFLAGS = -g -msoft-float +LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ + -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x + +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +iso: + mkpsxiso -y -q iso.xml + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/cdrom/cdbrowse/system.cnf b/examples/cdrom/cdbrowse/system.cnf new file mode 100644 index 0000000..9cf5593 --- /dev/null +++ b/examples/cdrom/cdbrowse/system.cnf @@ -0,0 +1,4 @@ +BOOT=cdrom:\cdbrowse.exe;1 +TCB=4 +EVENT=10 +STACK=801FFFF0 diff --git a/examples/cdrom/cdxa/ball16c.h b/examples/cdrom/cdxa/ball16c.h new file mode 100644 index 0000000..c79f273 --- /dev/null +++ b/examples/cdrom/cdxa/ball16c.h @@ -0,0 +1,16 @@ +unsigned int ball16c_size=192; +unsigned char ball16c[] = { +0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, +0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, +0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, +0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, +0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, +0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, +0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, +0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, +0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, +0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, +0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, +0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, +0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 +}; diff --git a/examples/cdrom/cdxa/iso.xml b/examples/cdrom/cdxa/iso.xml new file mode 100644 index 0000000..840b414 --- /dev/null +++ b/examples/cdrom/cdxa/iso.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/cdrom/cdxa/main.c b/examples/cdrom/cdxa/main.c new file mode 100644 index 0000000..55cb508 --- /dev/null +++ b/examples/cdrom/cdxa/main.c @@ -0,0 +1,551 @@ +/* + * LibPSn00b Example Programs + * + * CD-XA Audio Example + * 2019 Meido-Tek Productions / PSn00bSDK Project + * + * Demonstrates playback and looping of CD-XA audio using the + * new libpsxcd library. + * + * + * Since there is not yet an open source XA audio encoder yet, the + * only way to create XA audio data is by using the official tools. + * You will have to provide your own XA file to get this example + * to work. + * + * You will also need MKPSXISO (https://github.com/lameguy64/mkpsxiso) + * to build an ISO image with your XA audio data. + * + * + * Theory of operation: + * + * CD-XA playback is accomplished by first locating the XA file in + * the ISO9660 file system using CdSearchFile(). CD mode is then set + * using the CdlSetmode command with CdlModeSpeed, CdlModeRT and + * CdlModeSF flags to configure the CD controller for XA audio + * streaming. Trying to play XA audio without CdlModeSF, which + * enables filtering, will feed all XA channels to the SPU resulting + * in a stuttery cacophony of sounds. + * + * The XA channel for playback is selected using the CdlSetfilter + * command and CdlFILTER struct. XA audio is usually comprised of + * multiple audio streams interleaved together and this command + * sets which channel to filter in from all the other channels. + * CdlModeSF enables the filtering feature and is required when + * playing back XA audio streams with multiple interleaved sound + * channels. + * + * Playback is initiated by issuing CdlReadS with the XA file's + * location specified as a parameter, which is internally issued + * to the CD controller as the seek target before CdlReadS is + * actually issued. + * + * Playback can be stopped by simply issuing CdlPause during playback. + * It is not recommended to use CdlStop as it will stop the disc spinning + * and result to much slower response once the disc has stopped. + * + * The most effective method of determining the end of an XA stream is + * by hooking a callback routine with CdReadyCallback(), which is + * triggered whenever a data sector has been read and checking the + * header of the received sector if it belongs to the channel currently + * being played. + * + * Additionally, XA audio data must be encoded with video sectors at + * the end of each XA stream to serve as a terminator marker which + * triggers CdReadyCallback() during playback. From within the callback + * a CdlReadS command with the location of the XA data can be issued again + * to repeat the track or CdlPause to stop playback. + * + * + * Tips: + * + * - For best efficiency, it is recommended to have all XA tracks in + * a single XA file have roughly the same length to one another, + * otherwise tracks that end short will be padded with empty sectors + * which wastes potentially usable disc space. + * + * - The CD filter can be changed during playback and the switchover is + * completely seamless. Use this trick to accomplish dynamic music + * effects that change seamlessly based on events during gameplay. + * + * - With custom tools, it is possible to interleave data sectors with + * a single XA audio stream which would permit music playback during + * loading sessions (aside from using sequenced music). Alternatively, + * CdlReadN can be used to begin playback but with more reliable data + * reading. This is also how streaming FMV sequences are accomplished. + * + * + * Pros over CD audio: + * + * - Does not require changing disc speed when switching between data + * access and audio playback. + * + * - Permits switching between streams during playback without restart. + * + * - Near 1:4 audio compression ratio. + * + * - Data sectors can be interleaved alongside XA audio. + * + * + * Cons compared to CD audio: + * + * - Skips more often on a poor condition disc or optical pick-up. + * + * - Cannot be played with any CD player. + * + * - Lower audio sample rate (37.8KHz whereas CD audio is 44.1KHz, not + * good for audiophools). + * + * + * Controls: + * + * Up/Down - Select channel. + * Cross - Play selected channel. + * Circle - Stop selected channel. + * Right - Switch channel (without restarting playback). + * + * + * Example by Lameguy64 + * + * + * Changelog: + * + * November 22, 2019 - Initial version + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "ball16c.h" + + +#define MAX_BALLS 1536 /* Number of balls to display */ + +#define OT_LEN 8 /* Ordering table length */ + + +/* Screen coordinates */ +#define SCREEN_XRES 320 +#define SCREEN_YRES 240 + +#define CENTER_X SCREEN_XRES/2 +#define CENTER_Y SCREEN_YRES/2 + + +/* Display and drawing environments */ +DISPENV disp[2]; +DRAWENV draw[2]; + +char pribuff[2][65536]; /* Primitive packet buffers */ +unsigned int ot[2][OT_LEN]; /* Ordering tables */ +char *nextpri; /* Pointer to next packet buffer offset */ +int db = 0; /* Double buffer index */ + + +/* Ball struct and array */ +typedef struct BALL_TYPE +{ + short x,y; + short xdir,ydir; + unsigned char r,g,b,p; +} BALL_TYPE; + +BALL_TYPE balls[MAX_BALLS]; + + +/* TIM image parameters for loading the ball texture and drawing sprites */ +TIM_IMAGE tim; + + +/* XA audio handling stuff */ +volatile int num_loops=0; /* Loop counter */ +volatile int xa_play_channel; /* Currently playing channel number */ +CdlLOC xa_loc; /* XA data start location + + +/* Sector header structure for video sector terminator */ +typedef struct SECTOR_HEAD +{ + u_short id; + u_short chan; + u_char pad[28]; +} SECTOR_HEAD; + + +/* Pad input buffer*/ +char padbuff[2][34]; + +char xa_sector_buff[2048]; + +/* Callback for detecting end of channel (hooked by CdReadyCallback) */ +void xa_callback(int intr, unsigned char *result) +{ + SECTOR_HEAD *sec; + + /* Only respond to data ready callbacks */ + if (intr == CdlDataReady) + { + /* Fetch data sector */ + CdGetSector((u_long*)&xa_sector_buff, 2048); + + /* Quirk: This CdGetSector() implementation must fetch 2048 bytes */ + /* or more otherwise the following sectors will be read in an */ + /* incorrect byte order, probably due to stray data in the data */ + /* FIFO. Trying to flush remaining bytes in the FIFO through */ + /* memory reads after DMA transfer yields random deadlocking on */ + /* real hardware for some reason. CdGetSector() probably reads */ + /* the data FIFO in software rather than DMA transfer whereas */ + /* CdGetSector2() uses DMA transfer in the official SDK. */ + + /* Check if sector belongs to the currently playing channel */ + sec = (SECTOR_HEAD*)xa_sector_buff; + + if( sec->id == 352 ) + { + // Debug + //printf("ID=%d CHAN=%d PL=%d\n", sec->id, (sec->chan>>10)&0xF, xa_play_channel); + + /* Check if sector is of the currently playing channel */ + if( ((sec->chan>>10)&0xF) == xa_play_channel ) + { + num_loops++; + + /* Retry playback by seeking to start of XA data and stream */ + CdControlF(CdlReadS, (u_char*)&xa_loc); + + /* Stop playback */ + //CdControlF(CdlPause, 0); + } + } + } +} + +void init() +{ + int i; + + /* Reset GPU (also installs event handler for VSync) */ + printf("Init GPU... "); + ResetGraph( 0 ); + printf("Done.\n"); + + + /* Uncomment to direct tty messages to serial */ + AddSIO(115200); + + + /* Initialize SPU and CD-ROM */ + printf("Initializing CD-ROM... "); + SpuInit(); + CdInit(); + printf("Done.\n"); + + + /* Set display and draw environment parameters */ + SetDefDispEnv(&disp[0], 0, 0, SCREEN_XRES, SCREEN_YRES); + SetDefDispEnv(&disp[1], 0, SCREEN_YRES, SCREEN_XRES, SCREEN_YRES); + + SetDefDrawEnv(&draw[0], 0, SCREEN_YRES, SCREEN_XRES, SCREEN_YRES); + SetDefDrawEnv(&draw[1], 0, 0, SCREEN_XRES, SCREEN_YRES); + + + /* Set clear color, area clear and dither processing */ + setRGB0(&draw[0], 63, 0, 127); + draw[0].isbg = 1; + draw[0].dtd = 1; + setRGB0(&draw[1], 63, 0, 127); + draw[1].isbg = 1; + draw[1].dtd = 1; + + + /* Load and open font stream */ + FntLoad(960, 0); + FntOpen(32, 32, 256, 176, 2, 200); + + + /* Upload the ball texture */ + GetTimInfo((unsigned int*)ball16c, &tim); /* Get TIM parameters */ + LoadImage(tim.prect, tim.paddr); /* Upload texture to VRAM */ + if( tim.mode & 0x8 ) + { + LoadImage(tim.crect, tim.caddr); /* Upload CLUT if present */ + } + + + /* Calculate ball positions */ + printf("Calculating balls... "); + + for(i=0; istat == 0 ) + { + if(( pad->type == 0x4 )||( pad->type == 0x5 )||( pad->type == 0x7 )) + { + /* Menu selection controls */ + if( !(pad->btn&PAD_UP) ) + { + if( !p_up ) + { + if( sel_channel > 0 ) + { + sel_channel--; + } + p_up = 1; + } + } + else + { + p_up = 0; + } + + if( !(pad->btn&PAD_DOWN) ) + { + if( !p_down ) + { + if( sel_channel < 7 ) + { + sel_channel++; + } + p_down = 1; + } + } + else + { + p_down = 0; + } + + /* Play selected XA channel from start */ + if( !(pad->btn&PAD_CROSS) ) + { + if( !p_cross ) + { + filter.chan = sel_channel; + CdControl(CdlSetfilter, (u_char*)&filter, 0); + CdControl(CdlReadS, (u_char*)&xa_loc, 0); + xa_play_channel = sel_channel; + p_cross = 1; + } + } + else + { + p_cross = 0; + } + + /* Stop playback */ + if( !(pad->btn&PAD_CIRCLE) ) + { + if( !p_circle ) + { + CdControl(CdlPause, 0, 0); + p_circle = 1; + } + } + else + { + p_circle = 0; + } + + /* Change XA channel */ + if( !(pad->btn&PAD_RIGHT) ) + { + if( !p_right ) + { + filter.chan = sel_channel; + CdControl(CdlSetfilter, (u_char*)&filter, 0); + xa_play_channel = sel_channel; + p_right = 1; + } + } + else + { + p_right = 0; + } + + } + } + + + /* Display information */ + FntPrint(-1, "\n PSN00BSDK XA AUDIO EXAMPLE\n\n"); + FntPrint(-1, " CHANNEL:\n"); + + for(i=0; i<8; i++) + { + if( i == sel_channel ) + { + FntPrint(-1, " -->%d\n", i); + } + else + { + FntPrint(-1, " %d\n", i); + } + } + + FntPrint(-1, "\n CURRENT=%d STATUS=%x LOOPS=%d\n", + xa_play_channel, CdStatus(), num_loops); + FntPrint(-1, "\n -PLAY (START) -STOP\n -SET CHANNEL\n"); + + + /* Clear ordering table and set start address of primitive buffer */ + ClearOTagR(ot[db], OT_LEN); + nextpri = pribuff[db]; + + + /* Sort the balls */ + sprt = (SPRT_16*)nextpri; + for( i=0; ix, tim.crect->y); + + addPrim(ot[db]+(OT_LEN-1), sprt); + sprt++; + + balls[i].x += balls[i].xdir; + balls[i].y += balls[i].ydir; + + if( ( balls[i].x+16 ) > SCREEN_XRES ) { + balls[i].xdir = -2; + } else if( balls[i].x < 0 ) { + balls[i].xdir = 2; + } + + if( ( balls[i].y+16 ) > SCREEN_YRES ) { + balls[i].ydir = -2; + } else if( balls[i].y < 0 ) { + balls[i].ydir = 2; + } + + } + nextpri = (char*)sprt; + + + /* Sort a TPage primitive so the sprites will draw pixels from */ + /* the correct texture page in VRAM */ + tpri = (DR_TPAGE*)nextpri; + setDrawTPage(tpri, 0, 0, getTPage(0, 0, tim.prect->x, tim.prect->y)); + addPrim(ot[db]+(OT_LEN-1), tpri); + nextpri += sizeof(DR_TPAGE); + + /* Draw font */ + FntFlush(-1); + + /* Wait for GPU and VSync */ + DrawSync(0); + VSync(0); + + /* Since draw.isbg is non-zero this clears the screen */ + PutDispEnv(&disp[db]); + PutDrawEnv(&draw[db]); + SetDispMask(1); + + /* Begin drawing the new frame */ + DrawOTag( ot[db]+(OT_LEN-1) ); + + /* Alternate to the next buffer */ + db = !db; + + /* Periodically issue CdlNop every second to update CdStatus() */ + counter++; + if( (counter%60) == 59 ) + { + CdControl(CdlNop, 0, 0); + } + + } + + return 0; + +} diff --git a/examples/cdrom/cdxa/makefile b/examples/cdrom/cdxa/makefile new file mode 100644 index 0000000..8858979 --- /dev/null +++ b/examples/cdrom/cdxa/makefile @@ -0,0 +1,52 @@ +include ../../sdk-common.mk + +TARGET = cdxa.elf + +CFILES = $(notdir $(wildcard *.c)) +CPPFILES = $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) + +PREFIX = mipsel-unknown-elf- + +LIBS = -lpsxcd -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxsio -lpsxapi -lc + +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +CPPFLAGS = $(CFLAGS) \ + -fno-exceptions \ + -fno-rtti \ + -fno-unwind-tables \ + -fno-threadsafe-statics \ + -fno-use-cxa-atexit + +AFLAGS = -g -msoft-float +LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ + -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x + +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +iso: + mkpsxiso -y -q iso.xml + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/cdrom/cdxa/system.cnf b/examples/cdrom/cdxa/system.cnf new file mode 100644 index 0000000..e61e50e --- /dev/null +++ b/examples/cdrom/cdxa/system.cnf @@ -0,0 +1,4 @@ +BOOT=cdrom:\cdxa.exe;1 +TCB=4 +EVENT=10 +STACK=801FFFF0 diff --git a/examples/cdxa/ball16c.h b/examples/cdxa/ball16c.h deleted file mode 100644 index c79f273..0000000 --- a/examples/cdxa/ball16c.h +++ /dev/null @@ -1,16 +0,0 @@ -unsigned int ball16c_size=192; -unsigned char ball16c[] = { -0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, -0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, -0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, -0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, -0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, -0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, -0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, -0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, -0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, -0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, -0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, -0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, -0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 -}; diff --git a/examples/cdxa/iso.xml b/examples/cdxa/iso.xml deleted file mode 100644 index 840b414..0000000 --- a/examples/cdxa/iso.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/cdxa/main.c b/examples/cdxa/main.c deleted file mode 100644 index 55cb508..0000000 --- a/examples/cdxa/main.c +++ /dev/null @@ -1,551 +0,0 @@ -/* - * LibPSn00b Example Programs - * - * CD-XA Audio Example - * 2019 Meido-Tek Productions / PSn00bSDK Project - * - * Demonstrates playback and looping of CD-XA audio using the - * new libpsxcd library. - * - * - * Since there is not yet an open source XA audio encoder yet, the - * only way to create XA audio data is by using the official tools. - * You will have to provide your own XA file to get this example - * to work. - * - * You will also need MKPSXISO (https://github.com/lameguy64/mkpsxiso) - * to build an ISO image with your XA audio data. - * - * - * Theory of operation: - * - * CD-XA playback is accomplished by first locating the XA file in - * the ISO9660 file system using CdSearchFile(). CD mode is then set - * using the CdlSetmode command with CdlModeSpeed, CdlModeRT and - * CdlModeSF flags to configure the CD controller for XA audio - * streaming. Trying to play XA audio without CdlModeSF, which - * enables filtering, will feed all XA channels to the SPU resulting - * in a stuttery cacophony of sounds. - * - * The XA channel for playback is selected using the CdlSetfilter - * command and CdlFILTER struct. XA audio is usually comprised of - * multiple audio streams interleaved together and this command - * sets which channel to filter in from all the other channels. - * CdlModeSF enables the filtering feature and is required when - * playing back XA audio streams with multiple interleaved sound - * channels. - * - * Playback is initiated by issuing CdlReadS with the XA file's - * location specified as a parameter, which is internally issued - * to the CD controller as the seek target before CdlReadS is - * actually issued. - * - * Playback can be stopped by simply issuing CdlPause during playback. - * It is not recommended to use CdlStop as it will stop the disc spinning - * and result to much slower response once the disc has stopped. - * - * The most effective method of determining the end of an XA stream is - * by hooking a callback routine with CdReadyCallback(), which is - * triggered whenever a data sector has been read and checking the - * header of the received sector if it belongs to the channel currently - * being played. - * - * Additionally, XA audio data must be encoded with video sectors at - * the end of each XA stream to serve as a terminator marker which - * triggers CdReadyCallback() during playback. From within the callback - * a CdlReadS command with the location of the XA data can be issued again - * to repeat the track or CdlPause to stop playback. - * - * - * Tips: - * - * - For best efficiency, it is recommended to have all XA tracks in - * a single XA file have roughly the same length to one another, - * otherwise tracks that end short will be padded with empty sectors - * which wastes potentially usable disc space. - * - * - The CD filter can be changed during playback and the switchover is - * completely seamless. Use this trick to accomplish dynamic music - * effects that change seamlessly based on events during gameplay. - * - * - With custom tools, it is possible to interleave data sectors with - * a single XA audio stream which would permit music playback during - * loading sessions (aside from using sequenced music). Alternatively, - * CdlReadN can be used to begin playback but with more reliable data - * reading. This is also how streaming FMV sequences are accomplished. - * - * - * Pros over CD audio: - * - * - Does not require changing disc speed when switching between data - * access and audio playback. - * - * - Permits switching between streams during playback without restart. - * - * - Near 1:4 audio compression ratio. - * - * - Data sectors can be interleaved alongside XA audio. - * - * - * Cons compared to CD audio: - * - * - Skips more often on a poor condition disc or optical pick-up. - * - * - Cannot be played with any CD player. - * - * - Lower audio sample rate (37.8KHz whereas CD audio is 44.1KHz, not - * good for audiophools). - * - * - * Controls: - * - * Up/Down - Select channel. - * Cross - Play selected channel. - * Circle - Stop selected channel. - * Right - Switch channel (without restarting playback). - * - * - * Example by Lameguy64 - * - * - * Changelog: - * - * November 22, 2019 - Initial version - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "ball16c.h" - - -#define MAX_BALLS 1536 /* Number of balls to display */ - -#define OT_LEN 8 /* Ordering table length */ - - -/* Screen coordinates */ -#define SCREEN_XRES 320 -#define SCREEN_YRES 240 - -#define CENTER_X SCREEN_XRES/2 -#define CENTER_Y SCREEN_YRES/2 - - -/* Display and drawing environments */ -DISPENV disp[2]; -DRAWENV draw[2]; - -char pribuff[2][65536]; /* Primitive packet buffers */ -unsigned int ot[2][OT_LEN]; /* Ordering tables */ -char *nextpri; /* Pointer to next packet buffer offset */ -int db = 0; /* Double buffer index */ - - -/* Ball struct and array */ -typedef struct BALL_TYPE -{ - short x,y; - short xdir,ydir; - unsigned char r,g,b,p; -} BALL_TYPE; - -BALL_TYPE balls[MAX_BALLS]; - - -/* TIM image parameters for loading the ball texture and drawing sprites */ -TIM_IMAGE tim; - - -/* XA audio handling stuff */ -volatile int num_loops=0; /* Loop counter */ -volatile int xa_play_channel; /* Currently playing channel number */ -CdlLOC xa_loc; /* XA data start location - - -/* Sector header structure for video sector terminator */ -typedef struct SECTOR_HEAD -{ - u_short id; - u_short chan; - u_char pad[28]; -} SECTOR_HEAD; - - -/* Pad input buffer*/ -char padbuff[2][34]; - -char xa_sector_buff[2048]; - -/* Callback for detecting end of channel (hooked by CdReadyCallback) */ -void xa_callback(int intr, unsigned char *result) -{ - SECTOR_HEAD *sec; - - /* Only respond to data ready callbacks */ - if (intr == CdlDataReady) - { - /* Fetch data sector */ - CdGetSector((u_long*)&xa_sector_buff, 2048); - - /* Quirk: This CdGetSector() implementation must fetch 2048 bytes */ - /* or more otherwise the following sectors will be read in an */ - /* incorrect byte order, probably due to stray data in the data */ - /* FIFO. Trying to flush remaining bytes in the FIFO through */ - /* memory reads after DMA transfer yields random deadlocking on */ - /* real hardware for some reason. CdGetSector() probably reads */ - /* the data FIFO in software rather than DMA transfer whereas */ - /* CdGetSector2() uses DMA transfer in the official SDK. */ - - /* Check if sector belongs to the currently playing channel */ - sec = (SECTOR_HEAD*)xa_sector_buff; - - if( sec->id == 352 ) - { - // Debug - //printf("ID=%d CHAN=%d PL=%d\n", sec->id, (sec->chan>>10)&0xF, xa_play_channel); - - /* Check if sector is of the currently playing channel */ - if( ((sec->chan>>10)&0xF) == xa_play_channel ) - { - num_loops++; - - /* Retry playback by seeking to start of XA data and stream */ - CdControlF(CdlReadS, (u_char*)&xa_loc); - - /* Stop playback */ - //CdControlF(CdlPause, 0); - } - } - } -} - -void init() -{ - int i; - - /* Reset GPU (also installs event handler for VSync) */ - printf("Init GPU... "); - ResetGraph( 0 ); - printf("Done.\n"); - - - /* Uncomment to direct tty messages to serial */ - AddSIO(115200); - - - /* Initialize SPU and CD-ROM */ - printf("Initializing CD-ROM... "); - SpuInit(); - CdInit(); - printf("Done.\n"); - - - /* Set display and draw environment parameters */ - SetDefDispEnv(&disp[0], 0, 0, SCREEN_XRES, SCREEN_YRES); - SetDefDispEnv(&disp[1], 0, SCREEN_YRES, SCREEN_XRES, SCREEN_YRES); - - SetDefDrawEnv(&draw[0], 0, SCREEN_YRES, SCREEN_XRES, SCREEN_YRES); - SetDefDrawEnv(&draw[1], 0, 0, SCREEN_XRES, SCREEN_YRES); - - - /* Set clear color, area clear and dither processing */ - setRGB0(&draw[0], 63, 0, 127); - draw[0].isbg = 1; - draw[0].dtd = 1; - setRGB0(&draw[1], 63, 0, 127); - draw[1].isbg = 1; - draw[1].dtd = 1; - - - /* Load and open font stream */ - FntLoad(960, 0); - FntOpen(32, 32, 256, 176, 2, 200); - - - /* Upload the ball texture */ - GetTimInfo((unsigned int*)ball16c, &tim); /* Get TIM parameters */ - LoadImage(tim.prect, tim.paddr); /* Upload texture to VRAM */ - if( tim.mode & 0x8 ) - { - LoadImage(tim.crect, tim.caddr); /* Upload CLUT if present */ - } - - - /* Calculate ball positions */ - printf("Calculating balls... "); - - for(i=0; istat == 0 ) - { - if(( pad->type == 0x4 )||( pad->type == 0x5 )||( pad->type == 0x7 )) - { - /* Menu selection controls */ - if( !(pad->btn&PAD_UP) ) - { - if( !p_up ) - { - if( sel_channel > 0 ) - { - sel_channel--; - } - p_up = 1; - } - } - else - { - p_up = 0; - } - - if( !(pad->btn&PAD_DOWN) ) - { - if( !p_down ) - { - if( sel_channel < 7 ) - { - sel_channel++; - } - p_down = 1; - } - } - else - { - p_down = 0; - } - - /* Play selected XA channel from start */ - if( !(pad->btn&PAD_CROSS) ) - { - if( !p_cross ) - { - filter.chan = sel_channel; - CdControl(CdlSetfilter, (u_char*)&filter, 0); - CdControl(CdlReadS, (u_char*)&xa_loc, 0); - xa_play_channel = sel_channel; - p_cross = 1; - } - } - else - { - p_cross = 0; - } - - /* Stop playback */ - if( !(pad->btn&PAD_CIRCLE) ) - { - if( !p_circle ) - { - CdControl(CdlPause, 0, 0); - p_circle = 1; - } - } - else - { - p_circle = 0; - } - - /* Change XA channel */ - if( !(pad->btn&PAD_RIGHT) ) - { - if( !p_right ) - { - filter.chan = sel_channel; - CdControl(CdlSetfilter, (u_char*)&filter, 0); - xa_play_channel = sel_channel; - p_right = 1; - } - } - else - { - p_right = 0; - } - - } - } - - - /* Display information */ - FntPrint(-1, "\n PSN00BSDK XA AUDIO EXAMPLE\n\n"); - FntPrint(-1, " CHANNEL:\n"); - - for(i=0; i<8; i++) - { - if( i == sel_channel ) - { - FntPrint(-1, " -->%d\n", i); - } - else - { - FntPrint(-1, " %d\n", i); - } - } - - FntPrint(-1, "\n CURRENT=%d STATUS=%x LOOPS=%d\n", - xa_play_channel, CdStatus(), num_loops); - FntPrint(-1, "\n -PLAY (START) -STOP\n -SET CHANNEL\n"); - - - /* Clear ordering table and set start address of primitive buffer */ - ClearOTagR(ot[db], OT_LEN); - nextpri = pribuff[db]; - - - /* Sort the balls */ - sprt = (SPRT_16*)nextpri; - for( i=0; ix, tim.crect->y); - - addPrim(ot[db]+(OT_LEN-1), sprt); - sprt++; - - balls[i].x += balls[i].xdir; - balls[i].y += balls[i].ydir; - - if( ( balls[i].x+16 ) > SCREEN_XRES ) { - balls[i].xdir = -2; - } else if( balls[i].x < 0 ) { - balls[i].xdir = 2; - } - - if( ( balls[i].y+16 ) > SCREEN_YRES ) { - balls[i].ydir = -2; - } else if( balls[i].y < 0 ) { - balls[i].ydir = 2; - } - - } - nextpri = (char*)sprt; - - - /* Sort a TPage primitive so the sprites will draw pixels from */ - /* the correct texture page in VRAM */ - tpri = (DR_TPAGE*)nextpri; - setDrawTPage(tpri, 0, 0, getTPage(0, 0, tim.prect->x, tim.prect->y)); - addPrim(ot[db]+(OT_LEN-1), tpri); - nextpri += sizeof(DR_TPAGE); - - /* Draw font */ - FntFlush(-1); - - /* Wait for GPU and VSync */ - DrawSync(0); - VSync(0); - - /* Since draw.isbg is non-zero this clears the screen */ - PutDispEnv(&disp[db]); - PutDrawEnv(&draw[db]); - SetDispMask(1); - - /* Begin drawing the new frame */ - DrawOTag( ot[db]+(OT_LEN-1) ); - - /* Alternate to the next buffer */ - db = !db; - - /* Periodically issue CdlNop every second to update CdStatus() */ - counter++; - if( (counter%60) == 59 ) - { - CdControl(CdlNop, 0, 0); - } - - } - - return 0; - -} diff --git a/examples/cdxa/makefile b/examples/cdxa/makefile deleted file mode 100644 index 57f1959..0000000 --- a/examples/cdxa/makefile +++ /dev/null @@ -1,59 +0,0 @@ -include ../sdk-common.mk - -TARGET = cdxa.elf - -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) - -PREFIX = mipsel-unknown-elf- - -# Include directories -INCLUDE = -I../../libpsn00b/include - -# Library directories, last entry must point toolchain libraries -LIBDIRS = -L../../libpsn00b - -LIBDIRS += -L$(GCC_BASE)/lib/gcc/mipsel-unknown-elf/$(GCC_VERSION) -INCLUDE += -I$(GCC_BASE)/lib/gcc/mipsel-unknown-elf/$(GCC_VERSION)/include - -LIBS = -lpsxcd -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxsio -lpsxapi -lc - -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) \ - -fno-exceptions \ - -fno-rtti \ - -fno-unwind-tables \ - -fno-threadsafe-statics \ - -fno-use-cxa-atexit - -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x - -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -AS = $(PREFIX)as -LD = $(PREFIX)ld - -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - mkpsxiso -y -q iso.xml - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/cdxa/system.cnf b/examples/cdxa/system.cnf deleted file mode 100644 index e61e50e..0000000 --- a/examples/cdxa/system.cnf +++ /dev/null @@ -1,4 +0,0 @@ -BOOT=cdrom:\cdxa.exe;1 -TCB=4 -EVENT=10 -STACK=801FFFF0 diff --git a/examples/childexec/ball16c.h b/examples/childexec/ball16c.h deleted file mode 100644 index c79f273..0000000 --- a/examples/childexec/ball16c.h +++ /dev/null @@ -1,16 +0,0 @@ -unsigned int ball16c_size=192; -unsigned char ball16c[] = { -0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, -0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, -0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, -0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, -0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, -0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, -0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, -0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, -0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, -0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, -0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, -0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, -0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 -}; diff --git a/examples/childexec/child.c b/examples/childexec/child.c deleted file mode 100644 index fb38b63..0000000 --- a/examples/childexec/child.c +++ /dev/null @@ -1,319 +0,0 @@ -#include -#include -#include -#include -#include -#include - -/* OT and Packet Buffer sizes */ -#define OT_LEN 256 -#define PACKET_LEN 1024 - -/* Screen resolution */ -#define SCREEN_XRES 320 -#define SCREEN_YRES 240 - -/* Screen center position */ -#define CENTERX SCREEN_XRES>>1 -#define CENTERY SCREEN_YRES>>1 - - -/* Double buffer structure */ -typedef struct { - DISPENV disp; /* Display environment */ - DRAWENV draw; /* Drawing environment */ - int ot[OT_LEN]; /* Ordering table */ - char p[PACKET_LEN]; /* Packet buffer */ -} DB; - -/* Double buffer variables */ -DB db[2]; -int db_active = 0; -char *db_nextpri; - - -/* For easier handling of vertex indices */ -typedef struct { - short v0,v1,v2,v3; -} INDEX; - -/* Cube vertices */ -SVECTOR cube_verts[] = { - { -100, -100, -100, 0 }, - { 100, -100, -100, 0 }, - { -100, 100, -100, 0 }, - { 100, 100, -100, 0 }, - { 100, -100, 100, 0 }, - { -100, -100, 100, 0 }, - { 100, 100, 100, 0 }, - { -100, 100, 100, 0 } -}; - -/* Cube face normals */ -SVECTOR cube_norms[] = { - { 0, 0, -ONE, 0 }, - { 0, 0, ONE, 0 }, - { 0, -ONE, 0, 0 }, - { 0, ONE, 0, 0 }, - { -ONE, 0, 0, 0 }, - { ONE, 0, 0, 0 } -}; - -/* Cube vertex indices */ -INDEX cube_indices[] = { - { 0, 1, 2, 3 }, - { 4, 5, 6, 7 }, - { 5, 4, 0, 1 }, - { 6, 7, 3, 2 }, - { 0, 2, 5, 7 }, - { 3, 1, 6, 4 } -}; - -/* Number of faces of cube */ -#define CUBE_FACES 6 - - -/* Light color matrix */ -/* Each column represents the color matrix of each light source and is */ -/* used as material color when using gte_ncs() or multiplied by a */ -/* source color when using gte_nccs(). 4096 is 1.0 in this matrix */ -/* A column of zeroes disables the light source. */ -MATRIX color_mtx = { - ONE, 0, 0, /* Red */ - ONE, 0, 0, /* Green */ - ONE, 0, 0 /* Blue */ -}; - -/* Light matrix */ -/* Each row represents a vector direction of each light source. */ -/* An entire row of zeroes disables the light source. */ -MATRIX light_mtx = { - /* X, Y, Z */ - -2048 , -2048 , -2048, - 0 , 0 , 0, - 0 , 0 , 0 -}; - -char pad_buff[2][34]; - -/* Function declarations */ -void init(); -void display(); - - -/* Main function */ -int main() { - - int i,p,xy_temp; - - SVECTOR rot = { 0 }; /* Rotation vector for Rotmatrix */ - VECTOR pos = { 0, 0, 400 }; /* Translation vector for TransMatrix */ - MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ - - POLY_F4 *pol4; /* Flat shaded quad primitive pointer */ - - - /* Init graphics and GTE */ - init(); - - - /* Main loop */ - while( 1 ) { - - PADTYPE *pad = (PADTYPE*)pad_buff[0]; - - if( pad->stat == 0 ) { - - // For digital pad, dual-analog and dual-shock - if( ( pad->type == 0x4 ) || ( pad->type == 0x5 ) || ( pad->type == 0x7 ) ) { - - if( !(pad->btn&PAD_SELECT) ) { - break; - } - - } - - } - - /* Set rotation and translation to the matrix */ - RotMatrix( &rot, &mtx ); - TransMatrix( &mtx, &pos ); - - /* Multiply light matrix by rotation matrix so light source */ - /* won't appear relative to the model's rotation */ - MulMatrix0( &light_mtx, &mtx, &lmtx ); - - /* Set rotation and translation matrix */ - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - /* Set light matrix */ - gte_SetLightMatrix( &lmtx ); - - /* Make the cube SPEEN */ - rot.vx += 16; - rot.vz += 16; - - - /* Draw the cube */ - pol4 = (POLY_F4*)db_nextpri; - - for( i=0; i>2) > OT_LEN ) - continue; - - /* Initialize a quad primitive */ - setPolyF4( pol4 ); - - /* Set the projected vertices to the primitive */ - gte_stsxy0( &pol4->x0 ); - gte_stsxy1( &pol4->x1 ); - gte_stsxy2( &pol4->x2 ); - - /* Compute the last vertex and set the result */ - gte_ldv0( &cube_verts[cube_indices[i].v3] ); - gte_rtps(); - gte_stsxy( &pol4->x3 ); - - /* Load primitive color even though gte_ncs() doesn't use it. */ - /* This is so the GTE will output a color result with the */ - /* correct primitive code. */ - gte_ldrgb( &pol4->r0 ); - - /* Load the face normal */ - gte_ldv0( &cube_norms[i] ); - - /* Normal Color Single */ - gte_ncs(); - - /* Store result to the primitive */ - gte_strgb( &pol4->r0 ); - - /* Sort primitive to the ordering table */ - addPrim( db[db_active].ot+(p>>2), pol4 ); - - /* Advance to make another primitive */ - pol4++; - - } - - /* Update nextpri variable */ - /* (IMPORTANT if you plan to sort more primitives after this) */ - db_nextpri = (char*)pol4; - - /* Swap buffers and draw the primitives */ - display(); - - } - - StopPAD(); - - return 0; - -} - -void init() { - - /* Reset the GPU, also installs a VSync event handler */ - ResetGraph( 0 ); - - /* Set display and draw environment areas */ - /* (display and draw areas must be separate, otherwise hello flicker) */ - SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - - /* Enable draw area clear and dither processing */ - setRGB0( &db[0].draw, 63, 0, 127 ); - db[0].draw.isbg = 1; - db[0].draw.dtd = 1; - - - /* Define the second set of display/draw environments */ - SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); - - setRGB0( &db[1].draw, 63, 0, 127 ); - db[1].draw.isbg = 1; - db[1].draw.dtd = 1; - - - /* Apply the drawing environment of the first double buffer */ - PutDrawEnv( &db[0].draw ); - - - /* Clear both ordering tables to make sure they are clean at the start */ - ClearOTagR( db[0].ot, OT_LEN ); - ClearOTagR( db[1].ot, OT_LEN ); - - /* Set primitive pointer address */ - db_nextpri = db[0].p; - - /* Initialize the GTE */ - InitGeom(); - - /* Set GTE offset (recommended method of centering) */ - gte_SetGeomOffset( CENTERX, CENTERY ); - - /* Set screen depth (basically FOV control, W/2 works best) */ - gte_SetGeomScreen( CENTERX ); - - /* Set light ambient color and light color matrix */ - gte_SetBackColor( 63, 63, 63 ); - gte_SetColorMatrix( &color_mtx ); - - InitPAD(pad_buff[0], 34, pad_buff[1], 34); - StartPAD(); - ChangeClearPAD(0); - -} - -void display() { - - /* Wait for GPU to finish drawing and vertical retrace */ - DrawSync( 0 ); - VSync( 0 ); - - /* Swap buffers */ - db_active ^= 1; - db_nextpri = db[db_active].p; - - /* Clear the OT of the next frame */ - ClearOTagR( db[db_active].ot, OT_LEN ); - - /* Apply display/drawing environments */ - PutDrawEnv( &db[db_active].draw ); - PutDispEnv( &db[db_active].disp ); - - /* Enable display */ - SetDispMask( 1 ); - - /* Start drawing the OT of the last buffer */ - DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); - -} \ No newline at end of file diff --git a/examples/childexec/child_exe.s b/examples/childexec/child_exe.s deleted file mode 100644 index 842ac88..0000000 --- a/examples/childexec/child_exe.s +++ /dev/null @@ -1,6 +0,0 @@ -.section .data - -.global child_exe # Insert spoopypasta -.type child_exe, @object -child_exe: - .incbin "child.exe" \ No newline at end of file diff --git a/examples/childexec/makefile b/examples/childexec/makefile deleted file mode 100644 index 9cf7218..0000000 --- a/examples/childexec/makefile +++ /dev/null @@ -1,38 +0,0 @@ -include ../sdk-common.mk - -INCLUDE += -LIBDIRS += - -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lc -lpsxapi - -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x - -LDFLAGS_P = $(LDFLAGS) -Ttext=0x80010000 -LDFLAGS_C = $(LDFLAGS) -Ttext=0x80030000 - -CC = $(PREFIX)gcc -LD = $(PREFIX)ld - -all: child parent - -child: build/child.o - $(LD) $(LDFLAGS_C) $(LIBDIRS) build/child.o $(LIBS) -o child.elf - elf2x child.elf - -parent: build/parent.o build/child_exe.o - $(LD) $(LDFLAGS_P) $(LIBDIRS) build/parent.o build/child_exe.o $(LIBS) -o parent.elf - elf2x parent.elf - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build parent.elf parent.exe child.elf child.exe diff --git a/examples/childexec/parent.c b/examples/childexec/parent.c deleted file mode 100644 index 7f577e4..0000000 --- a/examples/childexec/parent.c +++ /dev/null @@ -1,305 +0,0 @@ -/* - * LibPSn00b Example Programs - * - * Child Program Execution Example - * 2019 Meido-Tek Productions / PSn00bSDK Project - * - * This is a modification of the balls example, modified to execute - * a child program for this example. - * - * Example by Lameguy64 - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "ball16c.h" - - -#define MAX_BALLS 1024 - -#define OT_LEN 8 - -#define SCREEN_XRES 640 -#define SCREEN_YRES 480 - -#define CENTER_X SCREEN_XRES/2 -#define CENTER_Y SCREEN_YRES/2 - - -/* Display and drawing environments */ -DISPENV disp; -DRAWENV draw; - -char pribuff[2][65536]; /* Primitive packet buffers */ -unsigned int ot[2][OT_LEN]; /* Ordering tables */ -char *nextpri; /* Pointer to next packet buffer offset */ -int db = 0; /* Double buffer index */ - - -/* Ball struct and array */ -typedef struct { - short x,y; - short xdir,ydir; - unsigned char r,g,b,p; -} BALL_TYPE; - -BALL_TYPE balls[MAX_BALLS]; - - -/* TIM image parameters for loading the ball texture and drawing sprites */ -TIM_IMAGE tim; - - -void run_child(); - -char pad_buff[2][34]; - - -void init() { - - int i; - - /* Reset GPU (also installs event handler for VSync) */ - printf("Init GPU... "); - ResetGraph( 0 ); - printf("Done.\n"); - - - printf("Set video mode... "); - - /* Set display and draw environment parameters */ - SetDefDispEnv( &disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); - disp.isinter = 1; /* Enable interlace (required for hires) */ - - /* Set clear color, area clear and dither processing */ - setRGB0( &draw, 63, 0, 127 ); - draw.isbg = 1; - draw.dtd = 1; - - /* Apply the display and drawing environments */ - PutDispEnv( &disp ); - PutDrawEnv( &draw ); - - /* Enable video output */ - SetDispMask( 1 ); - - printf("Done.\n"); - - - /* Upload the ball texture */ - printf("Upload texture... "); - GetTimInfo( (unsigned int*)ball16c, &tim ); /* Get TIM parameters */ - - LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */ - if( tim.mode & 0x8 ) { - LoadImage( tim.crect, tim.caddr ); /* Upload CLUT if present */ - } - - printf("Done.\n"); - - - /* Calculate ball positions */ - printf("Calculating balls... "); - - for(i=0; istat == 0 ) { - - // For digital pad, dual-analog and dual-shock - if( ( pad->type == 0x4 ) || ( pad->type == 0x5 ) || ( pad->type == 0x7 ) ) { - - if( !(pad->btn&PAD_START) ) { - DrawSync(0); - run_child(); - } - - } - - } - - /* Clear ordering table and set start address of primitive */ - /* buffer for next frame */ - ClearOTagR( ot[db], OT_LEN ); - nextpri = pribuff[db]; - - /* Sort a balls snake */ - sprt = (SPRT_16*)nextpri; - srand( 64 ); - for( i=0; i<32; i++ ) { - - setSprt16( sprt ); - setXY0( sprt, - (CENTER_X-8)+(isin((counter-(i<<4))<<3)>>5), - (CENTER_Y-8)-(icos((counter-(i<<2))<<3)>>5) ); - setRGB0( sprt, rand()%256, rand()%256, rand()%256 ); - setUV0( sprt, 0, 0 ); - setClut( sprt, tim.crect->x, tim.crect->y ); - - addPrim( ot[db]+(OT_LEN-1), sprt ); - sprt++; - - } - - /* Sort the balls */ - for( i=0; ix, tim.crect->y ); - - addPrim( ot[db]+(OT_LEN-1), sprt ); - sprt++; - - balls[i].x += balls[i].xdir; - balls[i].y += balls[i].ydir; - - if( ( balls[i].x+16 ) > 640 ) { - balls[i].xdir = -2; - } else if( balls[i].x < 0 ) { - balls[i].xdir = 2; - } - - if( ( balls[i].y+16 ) > 480 ) { - balls[i].ydir = -2; - } else if( balls[i].y < 0 ) { - balls[i].ydir = 2; - } - - } - nextpri = (char*)sprt; - - - /* Sort a TPage primitive so the sprites will draw pixels from */ - /* the correct texture page in VRAM */ - tpri = (DR_TPAGE*)nextpri; - setDrawTPage( tpri, 0, 0, - getTPage( 0, 0, tim.prect->x, tim.prect->y ) ); - addPrim( ot[db]+(OT_LEN-1), tpri ); - nextpri += sizeof(DR_TPAGE); - - /* Wait for GPU and VSync */ - DrawSync( 0 ); - VSync( 0 ); - - /* Since draw.isbg is non-zero this clears the screen */ - PutDrawEnv( &draw ); - - /* Begin drawing the new frame */ - DrawOTag( ot[db]+(OT_LEN-1) ); - - /* Alternate to the next buffer */ - db = !db; - - /* Increment counter for the snake animation */ - counter++; - - } - - return 0; - -} - -// PS-EXE header structure -typedef struct { - char id[16]; - struct EXEC param; - char pad[1972]; -} EXE_HEAD; - -// Child program address -extern char child_exe[]; - -// Manually defined as its not defined in psxapi by default -void SetDefaultExitFromException(); - -void run_child() { - - // So child header is readable - EXE_HEAD *exe = (EXE_HEAD*)child_exe; - - // Copy child executable to its intended adddress - memcpy((void*)exe->param.t_addr, child_exe+2048, exe->param.t_size); - - // Enter critical section to prepare for program execution - EnterCriticalSection(); - - // Stop pads, enable auto acknowledge - StopPAD(); - ChangeClearPAD(1); - ChangeClearRCnt(3, 1); - - // Set default exception handler just in case - //SetDefaultExitFromException(); - - // Last three function calls could be relegated to - // a StopCallback() function in the future. - - // Execute child - printf("Child exec!\n"); - Exec(&exe->param, 0, 0); - - // Reset previous handler - EnterCriticalSection(); - RestartCallback(); - ExitCriticalSection(); - - // Re-init and re-enable pads - InitPAD(pad_buff[0], 34, pad_buff[1], 34); - StartPAD(); - ChangeClearPAD(0); - - // Set this program's display mode - PutDispEnv(&disp); - -} diff --git a/examples/demos/n00bdemo/data.h b/examples/demos/n00bdemo/data.h new file mode 100644 index 0000000..3be0e3d --- /dev/null +++ b/examples/demos/n00bdemo/data.h @@ -0,0 +1,12 @@ +#ifndef _DATA_H +#define _DATA_H + +extern unsigned char lz_resources[]; + +/*extern unsigned char smd_mtekdisk[]; +extern unsigned char smd_mtektext[]; +extern unsigned char smd_star[]; +extern unsigned char smd_psn00b[]; +extern unsigned char smd_scarletlogo[];*/ + +#endif \ No newline at end of file diff --git a/examples/demos/n00bdemo/data.s b/examples/demos/n00bdemo/data.s new file mode 100644 index 0000000..3ca33cb --- /dev/null +++ b/examples/demos/n00bdemo/data.s @@ -0,0 +1,31 @@ +.section .data + +.global lz_resources +.type lz_resources, @object +lz_resources: + .incbin "data.lzp" + +#.global smd_mtekdisk +#.type smd_mtekdisk, @object +#smd_mtekdisk: +# .incbin "data/mtekdisk.smd" + +#.global smd_mtektext +#.type smd_mtektext, @object +#smd_mtektext: +# .incbin "data/mtektext.smd" + +#.global smd_star +#.type smd_star, @object +#smd_star: +# .incbin "data/star.smd" + +#.global smd_psn00b +#.type smd_psn00b, @object +#smd_psn00b: +# .incbin "data/psn00blogo.smd" + +#.global smd_scarletlogo +#.type smd_scarletlogo, @object +#smd_scarletlogo: +# .incbin "data/scarletlogo.smd" \ No newline at end of file diff --git a/examples/demos/n00bdemo/data.xml b/examples/demos/n00bdemo/data.xml new file mode 100644 index 0000000..292a325 --- /dev/null +++ b/examples/demos/n00bdemo/data.xml @@ -0,0 +1,49 @@ + + + + + data/petscum16c.tim + data/bungirl.tim + + + data/clktower.tim + data/riftbld1.tim + data/riftbld2.tim + data/hatkid.tim + + data/celmapi.tim + + data/lamelotl16c.tim + data/n00blogo-pixel.tim + data/font.tim + + + + + + + data/mtekdisk.smd + data/mtektext.smd + data/star.smd + data/psn00blogo.smd + data/logo.smd + + + data/petscum.smd + data/bulb.smd + + + data/bungirl.smd + + data/star_mask.smd + data/timerift.smd + data/rbowshade.smd + + data/hatkid.smd + + + textures.qlp + + + + \ No newline at end of file diff --git a/examples/demos/n00bdemo/data/bulb.smd b/examples/demos/n00bdemo/data/bulb.smd new file mode 100644 index 0000000..9b77c6d Binary files /dev/null and b/examples/demos/n00bdemo/data/bulb.smd differ diff --git a/examples/demos/n00bdemo/data/bulb.smx b/examples/demos/n00bdemo/data/bulb.smx new file mode 100644 index 0000000..89225e6 --- /dev/null +++ b/examples/demos/n00bdemo/data/bulb.smx @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/demos/n00bdemo/data/bungirl.smd b/examples/demos/n00bdemo/data/bungirl.smd new file mode 100644 index 0000000..63f96b5 Binary files /dev/null and b/examples/demos/n00bdemo/data/bungirl.smd differ diff --git a/examples/demos/n00bdemo/data/bungirl.smx b/examples/demos/n00bdemo/data/bungirl.smx new file mode 100644 index 0000000..6093d70 --- /dev/null +++ b/examples/demos/n00bdemo/data/bungirl.smx @@ -0,0 +1,5608 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/demos/n00bdemo/data/bungirl.tim b/examples/demos/n00bdemo/data/bungirl.tim new file mode 100644 index 0000000..11ee9f4 Binary files /dev/null and b/examples/demos/n00bdemo/data/bungirl.tim differ diff --git a/examples/demos/n00bdemo/data/celmapi.bmp b/examples/demos/n00bdemo/data/celmapi.bmp new file mode 100644 index 0000000..f44f94f Binary files /dev/null and b/examples/demos/n00bdemo/data/celmapi.bmp differ diff --git a/examples/demos/n00bdemo/data/celmapi.tim b/examples/demos/n00bdemo/data/celmapi.tim new file mode 100644 index 0000000..c043e0b Binary files /dev/null and b/examples/demos/n00bdemo/data/celmapi.tim differ diff --git a/examples/demos/n00bdemo/data/clktower.tim b/examples/demos/n00bdemo/data/clktower.tim new file mode 100644 index 0000000..15c6edc Binary files /dev/null and b/examples/demos/n00bdemo/data/clktower.tim differ diff --git a/examples/demos/n00bdemo/data/font.bmp b/examples/demos/n00bdemo/data/font.bmp new file mode 100644 index 0000000..1d078f3 Binary files /dev/null and b/examples/demos/n00bdemo/data/font.bmp differ diff --git a/examples/demos/n00bdemo/data/font.tim b/examples/demos/n00bdemo/data/font.tim new file mode 100644 index 0000000..64cdad2 Binary files /dev/null and b/examples/demos/n00bdemo/data/font.tim differ diff --git a/examples/demos/n00bdemo/data/hatkid.png b/examples/demos/n00bdemo/data/hatkid.png new file mode 100644 index 0000000..369ce32 Binary files /dev/null and b/examples/demos/n00bdemo/data/hatkid.png differ diff --git a/examples/demos/n00bdemo/data/hatkid.smd b/examples/demos/n00bdemo/data/hatkid.smd new file mode 100644 index 0000000..a68f414 Binary files /dev/null and b/examples/demos/n00bdemo/data/hatkid.smd differ diff --git a/examples/demos/n00bdemo/data/hatkid.smx b/examples/demos/n00bdemo/data/hatkid.smx new file mode 100644 index 0000000..f9e8012 --- /dev/null +++ b/examples/demos/n00bdemo/data/hatkid.smx @@ -0,0 +1,1281 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/demos/n00bdemo/data/hatkid.tim b/examples/demos/n00bdemo/data/hatkid.tim new file mode 100644 index 0000000..b2e9318 Binary files /dev/null and b/examples/demos/n00bdemo/data/hatkid.tim differ diff --git a/examples/demos/n00bdemo/data/lamelotl16c.png b/examples/demos/n00bdemo/data/lamelotl16c.png new file mode 100644 index 0000000..67490c8 Binary files /dev/null and b/examples/demos/n00bdemo/data/lamelotl16c.png differ diff --git a/examples/demos/n00bdemo/data/lamelotl16c.tim b/examples/demos/n00bdemo/data/lamelotl16c.tim new file mode 100644 index 0000000..194c034 Binary files /dev/null and b/examples/demos/n00bdemo/data/lamelotl16c.tim differ diff --git a/examples/demos/n00bdemo/data/lightworld.smd b/examples/demos/n00bdemo/data/lightworld.smd new file mode 100644 index 0000000..4c1bb59 Binary files /dev/null and b/examples/demos/n00bdemo/data/lightworld.smd differ diff --git a/examples/demos/n00bdemo/data/lightworld.smx b/examples/demos/n00bdemo/data/lightworld.smx new file mode 100644 index 0000000..665e8c9 --- /dev/null +++ b/examples/demos/n00bdemo/data/lightworld.smx @@ -0,0 +1,1097 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/demos/n00bdemo/data/logo.smd b/examples/demos/n00bdemo/data/logo.smd new file mode 100644 index 0000000..9eb1954 Binary files /dev/null and b/examples/demos/n00bdemo/data/logo.smd differ diff --git a/examples/demos/n00bdemo/data/logo.smx b/examples/demos/n00bdemo/data/logo.smx new file mode 100644 index 0000000..1ed0549 --- /dev/null +++ b/examples/demos/n00bdemo/data/logo.smx @@ -0,0 +1,1169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/demos/n00bdemo/data/mtekdisk.smd b/examples/demos/n00bdemo/data/mtekdisk.smd new file mode 100644 index 0000000..f99bd46 Binary files /dev/null and b/examples/demos/n00bdemo/data/mtekdisk.smd differ diff --git a/examples/demos/n00bdemo/data/mtekdisk.smx b/examples/demos/n00bdemo/data/mtekdisk.smx new file mode 100644 index 0000000..fce2fa2 --- /dev/null +++ b/examples/demos/n00bdemo/data/mtekdisk.smx @@ -0,0 +1,379 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/demos/n00bdemo/data/mtektext.smd b/examples/demos/n00bdemo/data/mtektext.smd new file mode 100644 index 0000000..a158521 Binary files /dev/null and b/examples/demos/n00bdemo/data/mtektext.smd differ diff --git a/examples/demos/n00bdemo/data/mtektext.smx b/examples/demos/n00bdemo/data/mtektext.smx new file mode 100644 index 0000000..50aa59d --- /dev/null +++ b/examples/demos/n00bdemo/data/mtektext.smx @@ -0,0 +1,671 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/demos/n00bdemo/data/n00blogo-pixel.png b/examples/demos/n00bdemo/data/n00blogo-pixel.png new file mode 100644 index 0000000..db7aa89 Binary files /dev/null and b/examples/demos/n00bdemo/data/n00blogo-pixel.png differ diff --git a/examples/demos/n00bdemo/data/n00blogo-pixel.tim b/examples/demos/n00bdemo/data/n00blogo-pixel.tim new file mode 100644 index 0000000..c372593 Binary files /dev/null and b/examples/demos/n00bdemo/data/n00blogo-pixel.tim differ diff --git a/examples/demos/n00bdemo/data/petscum.smd b/examples/demos/n00bdemo/data/petscum.smd new file mode 100644 index 0000000..9a1c8eb Binary files /dev/null and b/examples/demos/n00bdemo/data/petscum.smd differ diff --git a/examples/demos/n00bdemo/data/petscum.smx b/examples/demos/n00bdemo/data/petscum.smx new file mode 100644 index 0000000..8f1b9e5 --- /dev/null +++ b/examples/demos/n00bdemo/data/petscum.smx @@ -0,0 +1,1093 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/demos/n00bdemo/data/petscum16c.png b/examples/demos/n00bdemo/data/petscum16c.png new file mode 100644 index 0000000..c9d115c Binary files /dev/null and b/examples/demos/n00bdemo/data/petscum16c.png differ diff --git a/examples/demos/n00bdemo/data/petscum16c.tim b/examples/demos/n00bdemo/data/petscum16c.tim new file mode 100644 index 0000000..18af842 Binary files /dev/null and b/examples/demos/n00bdemo/data/petscum16c.tim differ diff --git a/examples/demos/n00bdemo/data/psn00blogo.smd b/examples/demos/n00bdemo/data/psn00blogo.smd new file mode 100644 index 0000000..3c1412a Binary files /dev/null and b/examples/demos/n00bdemo/data/psn00blogo.smd differ diff --git a/examples/demos/n00bdemo/data/psn00blogo.smx b/examples/demos/n00bdemo/data/psn00blogo.smx new file mode 100644 index 0000000..0921b6c --- /dev/null +++ b/examples/demos/n00bdemo/data/psn00blogo.smx @@ -0,0 +1,745 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/demos/n00bdemo/data/rbowshade.smd b/examples/demos/n00bdemo/data/rbowshade.smd new file mode 100644 index 0000000..c218d05 Binary files /dev/null and b/examples/demos/n00bdemo/data/rbowshade.smd differ diff --git a/examples/demos/n00bdemo/data/rbowshade.smx b/examples/demos/n00bdemo/data/rbowshade.smx new file mode 100644 index 0000000..6648b5d --- /dev/null +++ b/examples/demos/n00bdemo/data/rbowshade.smx @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/demos/n00bdemo/data/riftbld1.tim b/examples/demos/n00bdemo/data/riftbld1.tim new file mode 100644 index 0000000..5581bb3 Binary files /dev/null and b/examples/demos/n00bdemo/data/riftbld1.tim differ diff --git a/examples/demos/n00bdemo/data/riftbld2.tim b/examples/demos/n00bdemo/data/riftbld2.tim new file mode 100644 index 0000000..4048024 Binary files /dev/null and b/examples/demos/n00bdemo/data/riftbld2.tim differ diff --git a/examples/demos/n00bdemo/data/star.smd b/examples/demos/n00bdemo/data/star.smd new file mode 100644 index 0000000..68a5725 Binary files /dev/null and b/examples/demos/n00bdemo/data/star.smd differ diff --git a/examples/demos/n00bdemo/data/star.smx b/examples/demos/n00bdemo/data/star.smx new file mode 100644 index 0000000..c91947e --- /dev/null +++ b/examples/demos/n00bdemo/data/star.smx @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/demos/n00bdemo/data/star_mask.smd b/examples/demos/n00bdemo/data/star_mask.smd new file mode 100644 index 0000000..fe624fe Binary files /dev/null and b/examples/demos/n00bdemo/data/star_mask.smd differ diff --git a/examples/demos/n00bdemo/data/star_mask.smx b/examples/demos/n00bdemo/data/star_mask.smx new file mode 100644 index 0000000..695bd47 --- /dev/null +++ b/examples/demos/n00bdemo/data/star_mask.smx @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/demos/n00bdemo/data/timerift.smd b/examples/demos/n00bdemo/data/timerift.smd new file mode 100644 index 0000000..dc22e4d Binary files /dev/null and b/examples/demos/n00bdemo/data/timerift.smd differ diff --git a/examples/demos/n00bdemo/data/timerift.smx b/examples/demos/n00bdemo/data/timerift.smx new file mode 100644 index 0000000..38d53f6 --- /dev/null +++ b/examples/demos/n00bdemo/data/timerift.smx @@ -0,0 +1,1085 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/demos/n00bdemo/disp.c b/examples/demos/n00bdemo/disp.c new file mode 100644 index 0000000..d798ee9 --- /dev/null +++ b/examples/demos/n00bdemo/disp.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include "smd.h" +#include "disp.h" + +DISPENV disp; +DRAWENV draw; + +char pribuff[2][131072]; +unsigned int ot[2][OT_LEN]; +char *nextpri; +int db = 0; + +MATRIX mtx; + + +void initDisplay() { + + ResetGraph( 3 ); + + if( GetVideoMode() == MODE_NTSC ) { + SetDefDispEnv( &disp, 0, 0, 640, 480 ); + SetDefDrawEnv( &draw, 0, 0, 640, 480 ); + scSetClipRect( 0, 0, 640, 480 ); + printf("NTSC System.\n"); + } else { + SetDefDispEnv( &disp, 0, 0, 640, 512 ); + SetDefDrawEnv( &draw, 0, 0, 640, 512 ); + scSetClipRect( 0, 0, 640, 512 ); + disp.screen.y = 20; + disp.screen.h = 256; + printf("PAL System.\n"); + } + + disp.isinter = 1; + draw.isbg = 1; + + PutDispEnv( &disp ); + PutDrawEnv( &draw ); + + ClearOTagR( ot[0], OT_LEN ); + ClearOTagR( ot[1], OT_LEN ); + nextpri = pribuff[0]; + + InitGeom(); + gte_SetGeomScreen( 320 ); + + if( GetVideoMode() == MODE_NTSC ) { + gte_SetGeomOffset( 320, 240 ); + } else { + gte_SetGeomOffset( 320, 256 ); + } + +} + +void display() { + + DrawSync(0); + VSync(0); + + PutDrawEnv( &draw ); + DrawOTag( ot[db]+OT_LEN-1 ); + + db ^= 1; + ClearOTagR( ot[db], OT_LEN ); + nextpri = pribuff[db]; + + SetDispMask( 1 ); + +} \ No newline at end of file diff --git a/examples/demos/n00bdemo/disp.h b/examples/demos/n00bdemo/disp.h new file mode 100644 index 0000000..ecf6dcf --- /dev/null +++ b/examples/demos/n00bdemo/disp.h @@ -0,0 +1,25 @@ +#ifndef _DISP_H +#define _DISP_H + +#include + +#define SCENE_TIME 60*15 + +#define CENTERX 320 +#define CENTERY 240 + +#define OT_LEN 260 + +void initDisplay(); +void display(); + +extern unsigned int ot[2][OT_LEN]; +extern char *nextpri; +extern int db; + +extern DISPENV disp; +extern DRAWENV draw; + +extern MATRIX mtx; + +#endif // _DISP_H \ No newline at end of file diff --git a/examples/demos/n00bdemo/lightdemo.c b/examples/demos/n00bdemo/lightdemo.c new file mode 100644 index 0000000..ff858c0 --- /dev/null +++ b/examples/demos/n00bdemo/lightdemo.c @@ -0,0 +1,494 @@ +#include +#include +#include +#include +#include "disp.h" +#include "smd.h" + +extern MATRIX lgt_colmtx; + +extern SMD *o_world; +extern SMD *o_lightbulb; + +void sort_overlay(int showlotl); + +void lightdemo() { + + /* + The point lighting demo is perhaps the most impressive part of + n00bDEMO. A more streamlined version of this demo where you control + various attributes of the light source such as position, intensity + and color might be made as a dedicated example program in the future. + + The point lighting trick is actually not that too complicated. You + basically calculate the distance and direction vector of two points + which are the light source and the vertex of a polygon. + + Calculating the normal whose result can later be used to calculate + the distance between two points is achieved with: + + vec_dir.vx = lgt_point.vx - pri_vert.vx; + vec_dir.vy = lgt_point.vy - pri_vert.vy; + vec_dir.vz = lgt_point.vz - pri_vert.vz; + + The intensity is calculated with (this might not be accurate but this + is faster than applying a square root): + + i = 4096 - ( ( + (vec_dir.vx*vec_dir.vx) + + (vec_dir.vy*vec_dir.vy) + + (vec_dir.vz*vec_dir.vz) ) >> 7 ); + + // Clip minimum intensity + if( i < 0 ) + i = 0; + + This intensity value is then used to set the color of the light source + through the light color matrix. + + col_mtx.m[0][0] = i; + col_mtx.m[1][0] = i; + col_mtx.m[2][0] = i; + gte_SetColorMatrix( &col_mtx ); + + The direction vector can then be used as the direction of the light + source. It is recommended to normalize it first to prevent possible + overflow related issues. + + VectorNormalS( &vec_dir, &vec_norm ); + + lgt_mtx.m[0][0] = vec_norm.vx; + lgt_mtx.m[0][1] = vec_norm.vy; + lgt_mtx.m[0][2] = vec_norm.vz; + + gte_SetLightMatrix( &lgt_mtx ); + + This operation is then performed for each point of a polygon to + achieve a nice smooth shaded point lighting effect. The macros used + are still the same as doing light source calculation with the GTE + the normal way. + + 3D geometry still requires normal data as with most lighting + processing operations. 'Flat' normals (faces with a single normal + vector) work best on flat surfaces while 'smooth' normals (faces with + normals on each point) work best on round or curved surfaces. + + */ + + int i,p_ang; + + SC_OT s_ot; + + SVECTOR rot; + VECTOR pos; + SMD_PRIM s_pri; + + VECTOR l_point; + SVECTOR nrm; + + MATRIX lmtx,llmtx,omtx; + + SVECTOR orot = { 0 }; + + int timeout = SCENE_TIME; + + + // Set clear color to black + setRGB0( &draw, 0, 0, 0 ); + + // Base values for the environment geometry + setVector( &pos, 0, 0, 600 ); + setVector( &rot, 512, 0, 0 ); + + // Set base tpage value for the SMD drawing routines + smdSetBaseTPage( 0x200 ); + + // Set back or ambient color to black for pure darkness + gte_SetBackColor( 0, 0, 0 ); + + memset( &llmtx, 0, sizeof(MATRIX) ); + + + // demo loop + while( 1 ) { + + char buff[32]; + + RotMatrix( &rot, &mtx ); + TransMatrix( &mtx, &pos ); + + rot.vy += 4; + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + + setVector( &l_point, (icos( p_ang )>>2)>>2, -350+(icos( p_ang<<1 )>>4), (isin( p_ang )>>2)>>2 ); + p_ang += 16; + + + // Begin parsing the SMD data of the environment + OpenSMD( o_world ); + + // Prototype point lighting renderer + while( ReadSMD( &s_pri ) ) { + + VECTOR v_dir; + SVECTOR v_nrm; + VECTOR v_sqr; + + int flg; + + if( s_pri.prim_id.texture ) { + + POLY_GT4 *pri; + + // Perform standard rotate, translate and perspective + // transformation of the geometry + pri = (POLY_GT4*)nextpri; + + gte_ldv3( + &o_world->p_verts[s_pri.v0], + &o_world->p_verts[s_pri.v1], + &o_world->p_verts[s_pri.v2] ); + + gte_rtpt(); + + gte_nclip(); // Backface culling + + gte_stopz( &flg ); + + if( flg < 0 ) + continue; + + gte_stsxy3( &pri->x0, &pri->x1, &pri->x2 ); + + gte_ldv0( &o_world->p_verts[s_pri.v3] ); + gte_rtps(); + + gte_avsz4(); // Depth sort + gte_stotz( &flg ); + + if( (flg>>2) >= OT_LEN ) + continue; + + gte_stsxy( &pri->x3 ); + + + // Load base color of polygon to GTE + gte_ldrgb( &s_pri.r0 ); + + // Load normal of polygon + gte_ldv0( &o_world->p_norms[s_pri.n0] ); + + // Calculate the direction between the vertex of the + // polygon and the light source + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v0].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v0].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v0].vz; + + // Calculate distance and light intensity using square + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + // Clip minimum intensity + if( i < 0 ) + i = 0; + + // Set intensity to color matrix + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + gte_SetColorMatrix( &llmtx ); + + // Normalize light direction and set it to light matrix + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + + // Calculate (output is retrieved through gte_strgb) + gte_nccs(); + + + // Repeat process for the next 3 vertices + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v1].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v1].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v1].vz; + + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + if( i < 0 ) + i = 0; + + + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + + gte_strgb( &pri->r0 ); + + gte_SetColorMatrix( &llmtx ); + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + gte_nccs(); + + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v2].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v2].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v2].vz; + + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + if( i < 0 ) + i = 0; + + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + + gte_strgb( &pri->r1 ); + + gte_SetColorMatrix( &llmtx ); + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + gte_nccs(); + + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v3].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v3].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v3].vz; + + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + if( i < 0 ) + i = 0; + + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + + gte_strgb( &pri->r2 ); + + gte_SetColorMatrix( &llmtx ); + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + gte_nccs(); + + setUV4( pri, + s_pri.tu0, s_pri.tv0, + s_pri.tu1, s_pri.tv1, + s_pri.tu2, s_pri.tv2, + s_pri.tu3, s_pri.tv3 ); + + pri->tpage = s_pri.tpage; + pri->clut = s_pri.clut; + + setPolyGT4( pri ); + addPrim( ot[db]+(flg>>2), pri ); + nextpri += sizeof(POLY_GT4); + + gte_strgb( &pri->r3 ); + + } else { + + POLY_G4 *pri; + + pri = (POLY_G4*)nextpri; + + gte_ldv3( + &o_world->p_verts[s_pri.v0], + &o_world->p_verts[s_pri.v1], + &o_world->p_verts[s_pri.v2] ); + + gte_rtpt(); + + gte_nclip(); + + gte_stopz( &flg ); + + if( flg < 0 ) + continue; + + gte_stsxy3( &pri->x0, &pri->x1, &pri->x2 ); + + gte_ldv0( &o_world->p_verts[s_pri.v3] ); + gte_rtps(); + + gte_avsz4(); + gte_stotz( &flg ); + + if( (flg>>2) >= OT_LEN ) + continue; + + gte_stsxy( &pri->x3 ); + + gte_ldrgb( &s_pri.r0 ); + gte_ldv0( &o_world->p_norms[s_pri.n0] ); + + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v0].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v0].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v0].vz; + + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + if( i < 0 ) + i = 0; + + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + gte_SetColorMatrix( &llmtx ); + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + gte_nccs(); + + + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v1].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v1].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v1].vz; + + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + if( i < 0 ) + i = 0; + + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + + gte_strgb( &pri->r0 ); + + gte_SetColorMatrix( &llmtx ); + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + gte_nccs(); + + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v2].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v2].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v2].vz; + + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + if( i < 0 ) + i = 0; + + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + + gte_strgb( &pri->r1 ); + + gte_SetColorMatrix( &llmtx ); + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + gte_nccs(); + + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v3].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v3].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v3].vz; + + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + if( i < 0 ) + i = 0; + + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + + gte_strgb( &pri->r2 ); + + gte_SetColorMatrix( &llmtx ); + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + gte_nccs(); + + setPolyG4( pri ); + addPrim( ot[db]+(flg>>2), pri ); + + nextpri += sizeof(POLY_G4); + + gte_strgb( &pri->r3 ); + + } + + } + + + // Sort the light bulb to represent the position of the light source + orot.vx += 32; + orot.vy += 32; + orot.vz += 32; + + RotMatrix( &orot, &omtx ); + TransMatrix( &omtx, &l_point ); + + CompMatrixLV( &mtx, &omtx, &mtx ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + s_ot.ot = ot[db]; + s_ot.otlen = OT_LEN; + s_ot.zdiv = 2; + s_ot.zoff = 0; + + nextpri = smdSortModel( &s_ot, nextpri, o_lightbulb ); + + + // Sort overlay and display + sort_overlay( 1 ); + + display(); + + timeout--; + if( timeout < 0 ) + break; + + } + +} \ No newline at end of file diff --git a/examples/demos/n00bdemo/logo.c b/examples/demos/n00bdemo/logo.c new file mode 100644 index 0000000..3fdef5e --- /dev/null +++ b/examples/demos/n00bdemo/logo.c @@ -0,0 +1,428 @@ +#include +#include +#include +#include +#include +#include +#include "malloc.h" +#include "smd.h" +#include "lzp.h" + +#include "disp.h" +#include "data.h" + +#define MAX_STARS 64 + + +typedef struct { + int x,y; + int xvel,yvel; + int scale; + int rot,rotv; +} PARTICLE; + +typedef struct { + unsigned int tag; + unsigned int tpage; + unsigned int mask1; + unsigned char r0,g0,b0,code; + short x0,y0; + short x1,y1; + short x2,y2; + short x3,y3; + unsigned int mask2; +} MASKP_F4; + +typedef struct { + unsigned int tag; + unsigned int tpage; + unsigned char r0,g0,b0,code; + short x0,y0; + short w,h; +} FADERECT; + + +SMD *o_psn00b, *o_n00blogo; + + +typedef struct { + unsigned int *prev; + unsigned int *next; + int size; +} NODE; + +void DumpHeap() { + + NODE *n = (NODE*)GetBSSend(); + + printf( "--\n" ); + + while( 1 ) { + + printf( "B:%08p P:%08p N:%08p SZ:%d BS:%d\n", + n, n->prev, n->next, n->size, + ((unsigned int)n->next - (unsigned int)n) ); + + if ( !n->next ) + break; + + n = (NODE*)n->next; + + } + +} + + +void intro() { + + SVECTOR quad_coords[] = { + { -100, -100, 0, 0 }, + { 100, -100, 0, 0 }, + { -100, 100, 0, 0 }, + { 100, 100, 0, 0 } + }; + + PARTICLE stars[MAX_STARS]; + + VECTOR mpos; + SVECTOR mrot,trot; + SC_OT s_ot; + + SMD *o_disk, *o_star, *o_text, *o_psn00b, *o_n00blogo; + + int i,count = 0; + + int logo_scale; + int logo_rot; + + int logo_yvel; + int logo_ypos; + int logo_step; + int logo_spin; + int logo_svel; + int logo_count = 0; + int logo_tscale; + + int logo_n00b_spin; + int logo_fade = 0; + + struct { + int step; + int yvel; + int ypos; + int rot; + int scale; + int spin; + int spinvel; + int tscale; + int trot; + } mtek = { + 0, + 0, + ONE*750, + -ONE*512, + ONE*7, + 0, + 0, + 3072, + 0 + }; + + struct { + VECTOR pos; + int scale; + int scarlet_spin; + } psn00b = { + { 0, 0, 0 }, + ONE, + 1024 + }; + + + i = lzpSearchFile( "mtekdisk", lz_resources ); + o_disk = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_disk, lz_resources, i ); + smdInitData( o_disk ); + + i = lzpSearchFile( "mtektext", lz_resources ); + o_text = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_text, lz_resources, i ); + smdInitData( o_text ); + + i = lzpSearchFile( "starsprite", lz_resources ); + o_star = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_star, lz_resources, i ); + smdInitData( o_star ); + + i = lzpSearchFile( "psn00blogo", lz_resources ); + o_psn00b = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_psn00b, lz_resources, i ); + smdInitData( o_psn00b ); + + i = lzpSearchFile( "n00blogo", lz_resources ); + o_n00blogo = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_n00blogo, lz_resources, i ); + smdInitData( o_n00blogo ); + + //DumpHeap(); + + + // Set some Scarlet global parameters + smdSetBaseTPage( 0x200 ); + + // Change clear color + setRGB0( &draw, 255, 255, 255 ); + + setVector( &trot, 0, 0, 0 ); + + + // Initialize stars + for( i=0; i 360 ) { + mtek.spin -= mtek.spinvel; + mtek.spinvel += 1280; + } + + setVector( &mpos, 0, -(mtek.ypos>>12)-20, 400 ); + setVector( &mrot, 0, mtek.spin>>12, mtek.rot>>12 ); + + RotMatrix( &mrot, &mtx ); + TransMatrix( &mtx, &mpos ); + setVector( &mpos, mtek.scale, mtek.scale, 4096 ); + ScaleMatrix( &mtx, &mpos ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+10, nextpri, o_disk ); + + + if( mtek.step > 0 ) { + + setVector( &mpos, 0, 180, 400 ); + TransMatrix( &mtx, &mpos ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+8, nextpri, o_text ); + + if( logo_count < 480 ) { + + SVECTOR srot; + + for( i=0; i>12, stars[i].y>>12, 320 ); + setVector( &srot, 0, 0, stars[i].rot>>12 ); + + stars[i].x += stars[i].xvel; + stars[i].y += stars[i].yvel; + + stars[i].yvel += 512; + stars[i].rot += stars[i].rotv; + + RotMatrix( &srot, &mtx ); + TransMatrix( &mtx, &mpos ); + + setVector( &mpos, stars[i].scale, stars[i].scale, 4096 ); + ScaleMatrix( &mtx, &mpos ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+6, nextpri, o_star ); + + } + + } + + } + + if( !mtek.step ) { + mtek.rot -= ONE*20; + } else if( mtek.step == 1 ) { + mtek.rot += ( -mtek.rot )>>4; + } + + + if( mtek.step < 2 ) { + mtek.scale += (ONE-mtek.scale )>>5; + mtek.yvel += 512; + mtek.ypos -= mtek.yvel; + } + + + if( ( mtek.ypos <= 0 ) && ( mtek.yvel > 0 ) ) { + mtek.yvel = -ONE*6; + mtek.step++; + } + + // Does the transition effect + if( logo_count > 480 ) { + + TILE *rect = (TILE*)nextpri; + + mtek.trot += 16; + + setTile( rect ); + setXY0( rect, 0, 0 ); + setWH( rect, 640, 511 ); + setRGB0( rect, 0, 0, 0 ); + addPrim( ot[db]+4, rect ); + nextpri += sizeof(TILE); + + setVector( &mrot, 0, 0, mtek.trot ); + setVector( &mpos, mtek.tscale, mtek.tscale, 4096 ); + + RotMatrix( &mrot, &mtx ); + ScaleMatrix( &mtx, &mpos ); + + gte_SetRotMatrix( &mtx ); + + for( i=0; i<6; i++ ) { + + MASKP_F4 *pol4 = (MASKP_F4*)nextpri; + + setVector( &mpos, -100+(100*(i%3)), -60+(120*(i/3)), 160 ); + TransMatrix( &mtx, &mpos ); + gte_SetTransMatrix( &mtx ); + + pol4->tag = 0x08000000; + pol4->tpage = 0xe1000020; + pol4->mask1 = 0xe6000001; + pol4->mask2 = 0xe6000002; + pol4->code = 0x2A; + + gte_ldv3( &quad_coords[0], &quad_coords[1], &quad_coords[2] ); + gte_rtpt(); + gte_stsxy0( &pol4->x0 ); + gte_ldv0( &quad_coords[3] ); + gte_rtps(); + gte_stsxy3( &pol4->x1, &pol4->x2, &pol4->x3 ); + setRGB0( pol4, 0, 0, 0 ); + + addPrim( ot[db]+4, pol4 ); + nextpri += sizeof(MASKP_F4); + + } + + mtek.tscale += ( -mtek.tscale )>>6; + + } + + } else { + + setRGB0( &draw, 0, 0, 0 ); + + } + + if( logo_count >= 480 ) { + + if( logo_count > 840 ) { + + psn00b.pos.vx += ((ONE*-450)-psn00b.pos.vx)>>4; + psn00b.pos.vy += ((ONE*350)-psn00b.pos.vy)>>4; + + setVector( &mpos, 0, 0, 600 ); + mpos.vx = psn00b.pos.vx>>12; + mpos.vy = psn00b.pos.vy>>12; + + psn00b.scale += ( 1536-psn00b.scale )>>4; + + setVector( &mrot, 0, 0, 0 ); + + RotMatrix( &mrot, &mtx ); + TransMatrix( &mtx, &mpos ); + + setVector( &mpos, psn00b.scale, psn00b.scale, ONE ); + + ScaleMatrix( &mtx, &mpos ); + + } else { + + setVector( &mpos, 0, 0, 600 ); + setVector( &mrot, 0, logo_n00b_spin, 0 ); + + RotMatrix( &mrot, &mtx ); + TransMatrix( &mtx, &mpos ); + + logo_n00b_spin += ( -logo_n00b_spin )>>6; + + } + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+3, nextpri, o_psn00b ); + + if( logo_count > 900 ) { + + setVector( &mpos, 0, 0, 250 ); + setVector( &mrot, psn00b.scarlet_spin, 0, 0 ); + + RotMatrix( &mrot, &mtx ); + TransMatrix( &mtx, &mpos ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+3, nextpri, o_n00blogo ); + + psn00b.scarlet_spin += ( -psn00b.scarlet_spin )>>6; + + } + + } + + if( logo_count > 1200 ) { + + FADERECT *fade = (FADERECT*)nextpri; + + fade->tag = 0x04000000; + fade->tpage = 0xe1000040; + fade->code = 0x62; + + setRGB0( fade, logo_fade, logo_fade, logo_fade ); + setXY0( fade, 0, 0 ); + setWH( fade, 640, 480 ); + addPrim( ot[db]+2, fade ); + + if( logo_fade < 250 ) { + logo_fade += 4; + } + + nextpri += sizeof(FADERECT); + + } + + display(); + + logo_count++; + + } + + free( o_disk ); + free( o_text ); + free( o_star ); + free( o_psn00b ); + free( o_n00blogo ); + +} diff --git a/examples/demos/n00bdemo/logo.h b/examples/demos/n00bdemo/logo.h new file mode 100644 index 0000000..6429c8e --- /dev/null +++ b/examples/demos/n00bdemo/logo.h @@ -0,0 +1,6 @@ +#ifndef _LOGO_H +#define _LOGO_H + +void intro(); + +#endif // _LOGO_H diff --git a/examples/demos/n00bdemo/main.c b/examples/demos/n00bdemo/main.c new file mode 100644 index 0000000..a6eb57e --- /dev/null +++ b/examples/demos/n00bdemo/main.c @@ -0,0 +1,650 @@ +/* + * LibPSn00b Example Programs + * + * n00bDEMO Source Code + * 2019 Meido-Tek Productions / PSn00bSDK Project + * + * To build, simply run make. Make sure you have the lzpack tool accessible + * through your PATH environment variable. + * + * Demo by Lameguy64 + * + * Changelog: + * + * Apr 4, 2019 - Some code clean-up and added more comments. + * + * Mar 20, 2019 - Initial completed version. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "malloc.h" +#include "smd.h" +#include "data.h" +#include "disp.h" +#include "logo.h" +#include "plasma_tbl.h" + + +// Standard light color matrix +MATRIX lgt_colmtx = { + //#1,#2,#3 + ONE, 0, 0, // R + ONE, 0, 0, // G + ONE, 0, 0 // B +}; + +// SMD data global pointers +SMD *o_rbowshade; +SMD *o_world, *o_lightbulb; +SMD *o_timerift, *o_star; +SMD *o_hatkid,*o_bungirl;; + +// TPage and CLUT globals +unsigned short lamelotl_tpage,psn00b_tpage; +unsigned short font_tpage,font_clut; +SPRT llotl_sprite; +SPRT psn00b_sprite; + + +// Some function definition +void sort_overlay(int showlotl); +void lightdemo(); + + +void UploadTIM(TIM_IMAGE *tim) { + + /* + Very simple texture upload function + */ + + LoadImage( tim->prect, tim->paddr ); + + if( tim->mode & 0x8 ) + LoadImage( tim->crect, tim->caddr ); + +} + +void loadTextures() { + + /* + Unpack textures from an embedded LZP archive and upload them to VRAM. + */ + int i; + int *tex_buff,*ttim,j; + TIM_IMAGE tim; + + i = lzpSearchFile( "textures", lz_resources ); + tex_buff = (int*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( tex_buff, lz_resources, i ); + + + for( j=0; jx, tim.prect->y )|0x200; + setSprt( &psn00b_sprite ); + setClut( &psn00b_sprite, tim.crect->x, tim.crect->y ); + setWH( &psn00b_sprite, tim.prect->w<<2, tim.prect->h ); + setUV0( &psn00b_sprite, (tim.prect->x%64)<<2, tim.prect->y ); + setRGB0( &psn00b_sprite, 128, 128, 128 ); + + + GetTimInfo( (unsigned int*)qlpFileAddr( + qlpFindFile( "lamelotl", tex_buff ), tex_buff ), &tim ); + + UploadTIM( &tim ); + + lamelotl_tpage = getTPage( 0, 0, tim.prect->x, tim.prect->y )|0x200; + setSprt( &llotl_sprite ); + setClut( &llotl_sprite, tim.crect->x, tim.crect->y ); + setWH( &llotl_sprite, tim.prect->w<<2, tim.prect->h ); + setUV0( &llotl_sprite, 0, 0 ); + setRGB0( &llotl_sprite, 128, 128, 128 ); + + + GetTimInfo( (unsigned int*)qlpFileAddr( + qlpFindFile( "celmap", tex_buff ), tex_buff ), &tim ); + + UploadTIM( &tim ); + + smdSetCelTex( getTPage( 0, 2, tim.prect->x, tim.prect->y )|0x200, + getClut( tim.crect->x, tim.crect->y ) ); + smdSetCelParam( 3, 3, 0x4f4f4f ); + + + GetTimInfo( (unsigned int*)qlpFileAddr( + qlpFindFile( "font", tex_buff ), tex_buff ), &tim ); + + UploadTIM( &tim ); + + font_tpage = getTPage( 0, 1, tim.prect->x, tim.prect->y )|0x200; + font_clut = getClut( tim.crect->x, tim.crect->y ); + +} + +void unpackModels() { + + /* + Unpack model data from an embedded LZP archive. + */ + + int i; + + i = lzpSearchFile( "rbowshade", lz_resources ); + o_rbowshade = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_rbowshade, lz_resources, i ); + smdInitData( o_rbowshade ); + + i = lzpSearchFile( "bungirl", lz_resources ); + o_bungirl = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_bungirl, lz_resources, i ); + smdInitData( o_bungirl ); + + i = lzpSearchFile( "lightworld", lz_resources ); + o_world = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_world, lz_resources, i ); + smdInitData( o_world ); + + i = lzpSearchFile( "lightbulb", lz_resources ); + o_lightbulb = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_lightbulb, lz_resources, i ); + smdInitData( o_lightbulb ); + + i = lzpSearchFile( "timerift", lz_resources ); + o_timerift = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_timerift, lz_resources, i ); + smdInitData( o_timerift ); + + i = lzpSearchFile( "starmask", lz_resources ); + o_star = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_star, lz_resources, i ); + smdInitData( o_star ); + + i = lzpSearchFile( "hatkid", lz_resources ); + o_hatkid = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_hatkid, lz_resources, i ); + smdInitData( o_hatkid ); + +} + +void init() { + + int i; + + // Init display + initDisplay(); + + FntLoad( 960, 0 ); + + // Just to remove all sound + SpuInit(); + + // Load all textures + loadTextures(); + +} + +// Bungirl stuff +void bungirldemo() { + + /* + The bunny girl demo is just a simple demonstration of rendering a 1390 + polygon 3D model of a bunny girl with lighting using SMD drawing routines + from Scarlet Engine. + */ + + SC_OT s_ot; + + MATRIX lmtx; + + SVECTOR rot,brot,srot; + VECTOR pos; + + int timeout = SCENE_TIME; + + // Set clear color + setRGB0( &draw, 63, 0, 127 ); + + // Set tpage base value for SMD drawing routines + smdSetBaseTPage( 0x200 ); + + // Set initial rotation values + setVector( &rot, 192, 0, 0 ); + setVector( &brot, 0, 0, 128 ); + setVector( &srot, 0, 0, 0 ); + + // Set lighting color matrix + gte_SetColorMatrix( &lgt_colmtx ); + + // Set 'backside' or ambient light color + gte_SetBackColor( 113, 113, 113 ); + + + // Demo loop + while( 1 ) { + + // Bungirl position + setVector( &pos, 0, 50, 350 ); + + TransMatrix( &mtx, &pos ); + RotMatrix( &brot, &mtx ); + + // Calculate light matrix + lmtx.m[0][0] = isin( -brot.vy<<2 ); + lmtx.m[0][1] = -2048; + lmtx.m[0][2] = icos( -brot.vy<<2 ); + + MulMatrix0( &lmtx, &mtx, &lmtx ); + + // Set matrices + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + gte_SetLightMatrix( &lmtx ); + + // Sort the bungirl model + s_ot.ot = ot[db]; + s_ot.otlen = OT_LEN; + s_ot.zdiv = 1; + s_ot.zoff = 0; + nextpri = smdSortModel( &s_ot, nextpri, o_bungirl ); + + + // Sort the rotating rainbow background + setVector( &pos, 0, 0, 200 ); + + TransMatrix( &mtx, &pos ); + RotMatrix( &srot, &mtx ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + nextpri = smdSortModelFlat( ot[db]+(OT_LEN-1), nextpri, o_rbowshade ); + + brot.vy += 8; + srot.vz += 4; + + + // Sort overlay then display + sort_overlay( 0 ); + + display(); + + timeout--; + if( timeout < 0 ) + break; + + } + +} + +// Stencil effect stuff +void stencilstuff() { + + /* + The stencil demo is achieved by utilizing the mask bit setting + primitive GP0(E6h). The structure of this primitive is defined as + DR_MASK initialized and set by setDrawMask(). These are not available + in Sony's SDK by default. + + The DR_MASK primitive controls mask bit operations for drawing + primitives such as setting mask bits on every pixel drawn or mask + bit test where pixels won't be drawn on pixels with the mask bit set. + It applies to most graphics drawing primitives except VRAM fill. + The mask bits are stored in the 16th bit of each pixel drawn. + + The semi-transparency bits of a texture always carry over as mask + bits in textured primitives. The only way to clear mask bits is by + using VRAM fill commands or drawing primitives with the set mask + bit operation disabled. + + The stencil effect featured in this demo is achieved by enabling set + mask bit with DR_MASK, drawing semi-transparent primitives using + additive blending but color is all zero to make it completely invisible + but is enough to update the mask bits, disable mask set bit but enable + mask test with DR_MASK and then drawing a rectangle that fills the + entire screen. Semi-transparency mask in textures must not be used when + drawing the scene that will be 'below' the mask layer. + */ + int timeout = SCENE_TIME; + + int spin=0; + + DR_MASK *mask; + TILE *rect; + + SC_OT s_ot; + + SVECTOR rot; + SVECTOR srot; + VECTOR pos; + + // Set clear color + setRGB0( &draw, 127, 0, 63 ); + + // Set tpage base value for SMD drawing routines + smdSetBaseTPage( 0x200 ); + + // Base rotation coordinates + setVector( &rot, 0, 0, 0 ); + setVector( &srot, 0, 0, 0 ); + + // Set perspective + gte_SetGeomScreen( 320 ); + + + // Demo loop + while( timeout > 0 ) { + + + // Draw the timerift background + setVector( &rot, 0, spin, 0 ); + setVector( &pos, 0, 0, 0 ); + + TransMatrix( &mtx, &pos ); + RotMatrix( &rot, &mtx ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + s_ot.ot = ot[db]; + s_ot.otlen = 32; + s_ot.zdiv = 2; + s_ot.zoff = 20; + + nextpri = smdSortModelFlat( ot[db]+(OT_LEN-1), nextpri, o_timerift ); + + + // Sort mask primitive that enables setting mask bits + mask = (DR_MASK*)nextpri; + setDrawMask( mask, 1, 0 ); + addPrim( ot[db]+20, mask ); + nextpri += sizeof(DR_MASK); + + + // Sort the stars + setVector( &rot, 0, 0, spin<<2 ); + setVector( &pos, + (isin(spin<<2)*icos(spin))>>16, + (icos(spin<<2)*isin(spin))>>16, 400 ); + + TransMatrix( &mtx, &pos ); + RotMatrix( &rot, &mtx ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+19, nextpri, o_star ); + + setVector( &rot, 0, 0, -spin<<2 ); + setVector( &pos, + (isin(-spin<<2)*icos(-spin))>>16, + (icos(-spin<<2)*isin(-spin))>>16, 400 ); + + TransMatrix( &mtx, &pos ); + RotMatrix( &rot, &mtx ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+19, nextpri, o_star ); + + + // Sort mask primitive that enables mask bit test + mask = (DR_MASK*)nextpri; + setDrawMask( mask, 0, 1 ); + addPrim( ot[db]+18, mask ); + nextpri += sizeof(DR_MASK); + + + // Sort rectangle that fills the screen + rect = (TILE*)nextpri; + setTile( rect ); + setXY0( rect, 0, 0 ); + setWH( rect, 640, 511 ); + setRGB0( rect, 128, 0, 255 ); + addPrim( ot[db]+17, rect ); + nextpri += sizeof(TILE); + + + // Clear all mask settings + mask = (DR_MASK*)nextpri; + setDrawMask( mask, 0, 0 ); + addPrim( ot[db]+15, mask ); + nextpri += sizeof(DR_MASK); + + + // Sort overlay then display + sort_overlay( 0 ); + + display(); + + spin += 4; + timeout--; + } + +} + +// Orbiting around cel-shaded hatkid stuff +void hatkidstuff() { + + /* + The cel-shading effect works in a similar manner as conventional + per-vertex light source calculation except the color values are used + in a different manner. The resulting color values are divided down + using bit shifts to fit as texture coordinates (usually within the + range of 0-31) which are then used to map to a shading map which is a + simple texture of 3 to 4 shading levels. This technique is very similar + to how cel-shading is achieved on the Gamecube except all the vertex to + texture coordinate conversion is all done on the GX itself. + + To achieve this effect on untextured and textured polygons seamlessly + the shading map is drawn over the original unshaded polygons of the + model as semi-transparent polygons with subtractive blending. The + shading map had to be inverted for this effect to work properly since + blending is subtractive and not multiplicative after all. + */ + + int timeout = SCENE_TIME; + int spin=0; + + SC_OT s_ot; + + MATRIX lmtx; + + SVECTOR rot; + VECTOR pos; + + // Set clear color + setRGB0( &draw, 127, 0, 63 ); + + // Sets base TPage value for SMD drawing routines + smdSetBaseTPage( 0x200 ); + + setVector( &rot, 0, 0, 0 ); + + // Set light color matrix + gte_SetColorMatrix( &lgt_colmtx ); + + // Set back/ambient color to black (required for good cel-shading) + gte_SetBackColor( 0, 0, 0 ); + + gte_SetGeomScreen( 320 ); + + // Demo loop + while( timeout > 0 ) { + + // Sort 3D timerift background + setVector( &rot, spin, spin, spin>>1 ); + setVector( &pos, 0, 0, 0 ); + + TransMatrix( &mtx, &pos ); + RotMatrix( &rot, &mtx ); + + // Fixed light source direction + lmtx.m[0][0] = -2048; + lmtx.m[0][1] = -2048; + lmtx.m[0][2] = -2048; + + // Multiply by rotation matrix to make it relative to the camera rotation + MulMatrix0( &lmtx, &mtx, &lmtx ); + + gte_SetLightMatrix( &lmtx ); + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+(OT_LEN-1), nextpri, o_timerift ); + + + // Sort the cel-shaded hatkid + setVector( &pos, 0, 0, 600 ); + TransMatrix( &mtx, &pos ); + gte_SetTransMatrix( &mtx ); + + s_ot.ot = ot[db]; + s_ot.otlen = 250; + s_ot.zdiv = 1; + s_ot.zoff = 0; + + nextpri = smdSortModelCel( &s_ot, nextpri, o_hatkid ); + + + // Sort overlay then display + sort_overlay( 1 ); + display(); + + spin += 8; + timeout--; + + } + +} + +// Plasma stuff +void genPlasma(char *out, int count); +char *sortPlasma(int *ot, char *pri, char *map); + +void plasmastuff() { + + DR_TPAGE* tp; + char plasbuff[1271]; + + int pcount = 0; + int timeout = SCENE_TIME; + + while( timeout > 0 ) { + + genPlasma( plasbuff, pcount ); + nextpri = sortPlasma( ot[db]+1, nextpri, plasbuff ); + + sort_overlay( 1 ); + + display(); + timeout--; + pcount++; + + } + +} + +// Simple stripe transition effect +void transition() { + + int i,count,comp; + int bheight[16] = { 0 }; + + TILE *tile = (TILE*)nextpri; + draw.isbg = 0; + + while( 1 ) { + + comp = 0; + + for( i=0; i<16; i++ ) { + + if( bheight[i] > 0 ) { + + + setTile( tile ); + setXY0( tile, 0, 32*i ); + setRGB0( tile, 0, 151, 255 ); + setWH( tile, 640, bheight[i] ); + addPrim( ot[db], tile ); + tile++; + + if( bheight[i] < 32 ) + bheight[i]++; + else + comp++; + + } + + } + + if( bheight[count>>1] == 0 ) + bheight[count>>1] = 1; + + display(); + count++; + + if( comp >= 16 ) + break; + + } + + DrawSync(0); + + draw.isbg = 1; + +} + +int main(int argc, const char *argv[]) { + + // Init + init(); + + // Do transition + transition(); + + // Do Meido-Tek, PSn00bSDK and n00bDEMO logo intros + intro(); + + // Unpack model data + unpackModels(); + + // Demo sequence loop + while( 1 ) { + + lightdemo(); + bungirldemo(); + stencilstuff(); + hatkidstuff(); + plasmastuff(); + + } + + return 0; +} \ No newline at end of file diff --git a/examples/demos/n00bdemo/makefile b/examples/demos/n00bdemo/makefile new file mode 100644 index 0000000..63dc345 --- /dev/null +++ b/examples/demos/n00bdemo/makefile @@ -0,0 +1,44 @@ +include ../../sdk-common.mk + +TARGET = demo.elf + +CFILES = $(notdir $(wildcard *.c)) +AFILES = $(notdir $(wildcard *.s)) + +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) + +INCLUDE += -I../../../libpsn00b/lzp + +LIBS = -llzp -lc -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc + +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +CPPFLAGS = $(CFLAGS) -fno-exceptions +AFLAGS = -g -msoft-float +LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x + +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: resources $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +resources: + lzpack data.xml + touch data.s + +iso: + mkpsxiso -y -q -o demo.iso iso.xml + +clean: + rm -rf build *.lzp *.qlp $(TARGET) $(TARGET:.elf=.exe) $(TARGET:.elf=.iso) diff --git a/examples/demos/n00bdemo/overlay.c b/examples/demos/n00bdemo/overlay.c new file mode 100644 index 0000000..847bc96 --- /dev/null +++ b/examples/demos/n00bdemo/overlay.c @@ -0,0 +1,199 @@ +#include +#include +#include +#include "disp.h" + +extern const char scroll_text[]; +extern unsigned short lamelotl_tpage,psn00b_tpage; +extern unsigned short font_tpage,font_clut; + +extern SPRT llotl_sprite; +extern SPRT psn00b_sprite; + +u_char font_width[] = { + 10 ,6 ,12 ,16 ,12 ,14 ,14 ,8 ,10 ,10 ,14 ,12 ,8 ,14 ,6 ,14 , + 14 ,6 ,12 ,13 ,14 ,14 ,14 ,14 ,14 ,14 ,6 ,8 ,12 ,14 ,12 ,14 , + 14 ,14 ,14 ,13 ,14 ,14 ,14 ,14 ,14 ,14 ,14 ,14 ,12 ,15 ,14 ,14 , + 14 ,14 ,14 ,13 ,14 ,15 ,15 ,16 ,16 ,16 ,16 ,10 ,14 ,10 ,14 ,14 , + 8 ,14 ,13 ,11 ,13 ,12 ,13 ,12 ,13 ,6 ,14 ,14 ,8 ,16 ,14 ,14 , + 14 ,14 ,13 ,12 ,12 ,14 ,14 ,14 ,13 ,13 ,14 ,10 ,6 ,10 ,16 ,16 +}; + +int scrolltext_pos = 640; +int scrolltext_cpos = 0; +int overlay_count = 0; + +void sort_overlay(int showlotl) { + + SPRT *spr; + SPRT_16 *spr16; + DR_TPAGE *tp; + POLY_G4 *quad; + LINE_G2 *line; + + int i = scrolltext_cpos; + int j, k, tx, par_end = 0; + + tx = scrolltext_pos; + + while( scroll_text[i] != 0 ) { + + if( scroll_text[i] == '\n' ) { + par_end = 1; + break; + } + + j = scroll_text[i]-32; + + if( j > 0 ) { + + spr16 = (SPRT_16*)nextpri; + setSprt16( spr16 ); + setSemiTrans( spr16, 1 ); + setXY0( spr16, tx, 28 ); + setUV0( spr16, (j%16)<<4, (j>>4)<<4 ); + + if( tx < 128 ) { + k = tx; + if( k < 0 ) + k = 0; + setRGB0( spr16, k, k, k ); + } else if( tx > 512 ) { + k = 128-(tx-512); + if( k < 0 ) + k = 0; + setRGB0( spr16, k, k, k ); + } else { + setRGB0( spr16, 128, 128, 128 ); + } + + spr16->clut = font_clut; + addPrim( ot[db], spr16 ); + nextpri += sizeof(SPRT_16); + + } + + tx += font_width[j]; + + if( tx > 640 ) + break; + + i++; + + } + + scrolltext_pos -= 4; + j = scroll_text[scrolltext_cpos]-32; + if( j >= 0 ) { + + if( scrolltext_pos <= -font_width[j] ) { + + scrolltext_pos += font_width[j]; + scrolltext_cpos++; + + } + + } else { + + scrolltext_pos = 0; + scrolltext_cpos++; + + if( par_end ) + scrolltext_pos = 640; + + if( scroll_text[scrolltext_cpos] == 0 ) { + scrolltext_cpos = 0; + scrolltext_pos = 640; + } + + } + + line = (LINE_G2*)nextpri; + setLineG2( line ); + setSemiTrans( line, 1 ); + setXY2( line, 0, 46, 320, 46 ); + setRGB0( line, 0, 0, 0 ); + setRGB1( line, 255, 255, 255 ); + addPrim( ot[db], line ); + line++; + setLineG2( line ); + setSemiTrans( line, 1 ); + setXY2( line, 320, 46, 640, 46 ); + setRGB0( line, 255, 255, 255 ); + setRGB1( line, 0, 0, 0 ); + addPrim( ot[db], line ); + line++; + nextpri = (char*)line; + + tp = (DR_TPAGE*)nextpri; + setDrawTPage( tp, 0, 1, font_tpage ); + addPrim( ot[db], tp ); + nextpri += sizeof(DR_TPAGE); + + quad = (POLY_G4*)nextpri; + setPolyG4( quad ); + setSemiTrans( quad, 1 ); + setXY4( quad, + 0, 25, 320, 25, + 0, 46, 320, 46 ); + setRGB0( quad, 0, 0, 0 ); + setRGB1( quad, 64, 64, 64 ); + setRGB2( quad, 0, 0, 0 ); + setRGB3( quad, 64, 64, 64 ); + addPrim( ot[db], quad ); + quad++; + setPolyG4( quad ); + setSemiTrans( quad, 1 ); + setXY4( quad, + 320, 25, 640, 25, + 320, 46, 640, 46 ); + setRGB0( quad, 64, 64, 64 ); + setRGB1( quad, 0, 0, 0 ); + setRGB2( quad, 64, 64, 64 ); + setRGB3( quad, 0, 0, 0 ); + addPrim( ot[db], quad ); + quad++; + nextpri = (char*)quad; + + i = isin( overlay_count )>>9; + + if( GetVideoMode() == MODE_PAL ) { + j = 32; + } else { + j = 0; + } + + tp = (DR_TPAGE*)nextpri; + setDrawTPage( tp, 0, 1, getTPage( 0, 2, 0, 0 ) ); + addPrim( ot[db], tp ); + nextpri += sizeof(DR_TPAGE); + + if( showlotl ) { + + spr = (SPRT*)nextpri; + *spr = llotl_sprite; + setXY0( spr, 440, (200+j)+i ); + addPrim( ot[db], spr ); + nextpri += sizeof(SPRT); + + tp = (DR_TPAGE*)nextpri; + setDrawTPage( tp, 0, 1, lamelotl_tpage ); + addPrim( ot[db], tp ); + nextpri += sizeof(DR_TPAGE); + + } + + spr = (SPRT*)nextpri; + *spr = psn00b_sprite; + setXY0( spr, 8, (400+j)-i ); + addPrim( ot[db], spr ); + nextpri += sizeof(SPRT); + + tp = (DR_TPAGE*)nextpri; + setDrawTPage( tp, 0, 1, psn00b_tpage ); + addPrim( ot[db], tp ); + nextpri += sizeof(DR_TPAGE); + + overlay_count += 32; + +} \ No newline at end of file diff --git a/examples/demos/n00bdemo/plasma_tbl.c b/examples/demos/n00bdemo/plasma_tbl.c new file mode 100644 index 0000000..af6654a --- /dev/null +++ b/examples/demos/n00bdemo/plasma_tbl.c @@ -0,0 +1,500 @@ +// These are from Meido-Demo which was a very simple demo I made back in 2013 +// Man, time sure does fly. - Lameguy64 + +unsigned int plasma_colors[256] = { + 0x00000000, + 0x00000408, + 0x00040811, + 0x0008111a, + 0x00081623, + 0x000d1f2c, + 0x00112335, + 0x0011273d, + 0x0016304a, + 0x001a3553, + 0x001f3d5b, + 0x001f4163, + 0x00234a6b, + 0x00274e73, + 0x0027537b, + 0x002c5b83, + 0x00305f8e, + 0x00356795, + 0x00356b9c, + 0x00396fa3, + 0x003d77aa, + 0x003d7bb1, + 0x004183b7, + 0x004687bd, + 0x00468ac6, + 0x004a92cb, + 0x004e95d0, + 0x00539cd5, + 0x0053a0da, + 0x0057a7df, + 0x005baae3, + 0x005bade7, + 0x005fb4ec, + 0x0063b7ef, + 0x0067bdf2, + 0x0067c0f5, + 0x006bc6f7, + 0x006fc8f9, + 0x006fcbfb, + 0x0073d0fc, + 0x0077d3fe, + 0x007bd8fe, + 0x007bdafe, + 0x007fdcfe, + 0x0083e1fe, + 0x0083e3fe, + 0x0087e7fd, + 0x008ae8fb, + 0x008eecf9, + 0x008eeef7, + 0x0092eff5, + 0x0095f2f2, + 0x0095f3ef, + 0x0099f6ec, + 0x009cf7e8, + 0x009cf8e5, + 0x00a0fadf, + 0x00a3fbda, + 0x00a7fcd5, + 0x00a7fdd0, + 0x00aafdcb, + 0x00adfec6, + 0x00adfec0, + 0x00b1feba, + 0x00b4ffb1, + 0x00b7feaa, + 0x00b7fea3, + 0x00bafe9c, + 0x00bdfd95, + 0x00bdfd8e, + 0x00c0fb87, + 0x00c3fb7f, + 0x00c3fa73, + 0x00c6f86b, + 0x00c8f763, + 0x00cbf55b, + 0x00cbf353, + 0x00cef14a, + 0x00d0ef41, + 0x00d0ee39, + 0x00d3ea2c, + 0x00d5e823, + 0x00d8e51a, + 0x00d8e311, + 0x00dae108, + 0x00dcdc00, + 0x00dcda08, + 0x00dfd511, + 0x00e1d31f, + 0x00e3ce27, + 0x00e3cb30, + 0x00e5c839, + 0x00e7c341, + 0x00e7c04a, + 0x00e8ba53, + 0x00eab75b, + 0x00eab467, + 0x00ecad6f, + 0x00eeaa77, + 0x00efa37f, + 0x00efa087, + 0x00f1998e, + 0x00f29595, + 0x00f2929c, + 0x00f38aa7, + 0x00f587ad, + 0x00f67fb4, + 0x00f67bba, + 0x00f773c0, + 0x00f86fc6, + 0x00f86bcb, + 0x00f963d0, + 0x00fa5fd8, + 0x00fb57dc, + 0x00fb53e1, + 0x00fb4ee5, + 0x00fc46e8, + 0x00fc41ec, + 0x00fd39ef, + 0x00fd35f2, + 0x00fe2cf6, + 0x00fe27f8, + 0x00fe23fa, + 0x00fe1afb, + 0x00fe16fd, + 0x00fe0dfe, + 0x00fe08fe, + 0x00fe04fe, + 0x00fe04fe, + 0x00fe08fe, + 0x00fe11fd, + 0x00fe16fc, + 0x00fe1ffb, + 0x00fe23f9, + 0x00fe27f7, + 0x00fe30f5, + 0x00fd35f1, + 0x00fd3dee, + 0x00fd41ea, + 0x00fc46e7, + 0x00fb4ee3, + 0x00fb53df, + 0x00fb5bda, + 0x00fa5fd5, + 0x00f967ce, + 0x00f96bc8, + 0x00f86fc3, + 0x00f777bd, + 0x00f77bb7, + 0x00f683b1, + 0x00f587aa, + 0x00f58aa3, + 0x00f39299, + 0x00f29592, + 0x00f19c8a, + 0x00f1a083, + 0x00efa77b, + 0x00eeaa73, + 0x00eead6b, + 0x00ecb463, + 0x00eab757, + 0x00e8bd4e, + 0x00e8c046, + 0x00e7c33d, + 0x00e5c835, + 0x00e5cb2c, + 0x00e3d023, + 0x00e1d31a, + 0x00dfd80d, + 0x00dfda04, + 0x00dcdc04, + 0x00dae10d, + 0x00dae316, + 0x00d8e71f, + 0x00d5e827, + 0x00d5ea30, + 0x00d3ee3d, + 0x00d0ef46, + 0x00cef24e, + 0x00cef357, + 0x00cbf65f, + 0x00c8f767, + 0x00c8f86f, + 0x00c6fa77, + 0x00c3fb83, + 0x00c0fc8a, + 0x00c0fd92, + 0x00bdfd99, + 0x00bafea0, + 0x00bafea7, + 0x00b7fead, + 0x00b4ffb4, + 0x00b1febd, + 0x00b1fec3, + 0x00adfec8, + 0x00aafdce, + 0x00aafdd3, + 0x00a7fbd8, + 0x00a3fbdc, + 0x00a3fae1, + 0x00a0f8e7, + 0x009cf7ea, + 0x0099f5ee, + 0x0099f3f1, + 0x0095f1f3, + 0x0092eff6, + 0x0092eef8, + 0x008eeafa, + 0x008ae8fc, + 0x0087e5fd, + 0x0087e3fe, + 0x0083e1fe, + 0x007fdcff, + 0x007fdafe, + 0x007bd5fe, + 0x0077d3fd, + 0x0073cefb, + 0x0073cbfa, + 0x006fc8f8, + 0x006bc3f6, + 0x006bc0f3, + 0x0067baf1, + 0x0063b7ee, + 0x0063b4ea, + 0x005fade5, + 0x005baae1, + 0x0057a3dc, + 0x0057a0d8, + 0x00539cd3, + 0x004e95ce, + 0x004e92c8, + 0x004a8ac3, + 0x004687ba, + 0x00417fb4, + 0x00417bad, + 0x003d77a7, + 0x00396fa0, + 0x00396b99, + 0x00356392, + 0x00305f8a, + 0x00305b7f, + 0x002c5377, + 0x00274e6f, + 0x00234667, + 0x0023415f, + 0x001f3957, + 0x001a354e, + 0x001a3046, + 0x00162739, + 0x00112330, + 0x000d1a27, + 0x000d161f, + 0x00081116, + 0x0004080d, + 0x00040404, + 0x00000404 +}; + +short plasma_sin1[] = { + 0, + 6, + 12, + 18, + 24, + 30, + 36, + 42, + 47, + 53, + 59, + 65, + 71, + 76, + 82, + 88, + 93, + 99, + 104, + 110, + 115, + 120, + 125, + 131, + 136, + 141, + 146, + 150, + 155, + 160, + 165, + 169, + 173, + 178, + 182, + 186, + 190, + 194, + 198, + 202, + 205, + 209, + 212, + 216, + 219, + 222, + 225, + 227, + 230, + 233, + 235, + 237, + 240, + 242, + 243, + 245, + 247, + 248, + 250, + 251, + 252, + 253, + 254, + 255, + 255, + 256, + 256, + 256, + 256, + 256, + 256, + 255, + 255, + 254, + 253, + 252, + 251, + 250, + 248, + 247, +}; + +short plasma_sin2[] = { + 0, + 4, + 9, + 13, + 17, + 21, + 24, + 27, + 29, + 30, + 32, + 32, + 32, + 31, + 30, + 28, + 25, + 22, + 19, + 15, + 11, + 7, + 2, + -2, + -7, + -11, + -15, + -19, + -22, + -25, + -28, + -30, + -31, + -32, + -32, + -32, + -30, + -29, + -27, + -24, + -21, + -17, + -13, + -9, + -4, + 0, + 4, + 9, + 13, + 17, + 21, + 24, + 27, + 29, + 30, + 32, + 32, + 32, + 31, + 30 +}; + +short plasma_sin3[] = { +0, + 4, + 9, + 13, + 18, + 22, + 26, + 30, + 34, + 38, + 41, + 44, + 48, + 50, + 53, + 55, + 58, + 59, + 61, + 62, + 63, + 64, + 64, + 64, + 64, + 63, + 62, + 61, + 59, + 58, + 55, + 53, + 50, + 48, + 44, + 41, + 38, + 34, + 30, + 26, + 22, + 18, + 13, + 9, + 4, + 0, + -4, + -9, + -13, + -18, + -22, + -26, + -30, + -34, + -38, + -41, + -44, + -48, + -50, + -53, + -55, + -58, + -59, + -61, + -62, + -63, + -64, + -64, + -64, + -64, + -63, + -62, + -61, + -59, + -58, + -55, + -53, + -50, + -48, + -44, + -41, + -38, + -34, + -30, + -26, + -22, + -18, + -13, + -9, + -4, +}; \ No newline at end of file diff --git a/examples/demos/n00bdemo/plasma_tbl.h b/examples/demos/n00bdemo/plasma_tbl.h new file mode 100644 index 0000000..dd322e6 --- /dev/null +++ b/examples/demos/n00bdemo/plasma_tbl.h @@ -0,0 +1,9 @@ +#ifndef _PLASMA_TBL_H +#define _PLASMA_TBL_H + +unsigned int plasma_colors[256]; +extern short plasma_sin1[]; +extern short plasma_sin2[]; +extern short plasma_sin3[]; + +#endif \ No newline at end of file diff --git a/examples/demos/n00bdemo/plasmagen.s b/examples/demos/n00bdemo/plasmagen.s new file mode 100644 index 0000000..07b3f48 --- /dev/null +++ b/examples/demos/n00bdemo/plasmagen.s @@ -0,0 +1,181 @@ +.set noreorder + +.set POLYG4_tag, 0 +.set POLYG4_rgb0, 4 +.set POLYG4_xy0, 8 +.set POLYG4_rgb1, 12 +.set POLYG4_xy1, 16 +.set POLYG4_rgb2, 20 +.set POLYG4_xy2, 24 +.set POLYG4_rgb3, 28 +.set POLYG4_xy3, 32 +.set POLYG4_len, 36 + +# a0 - Plasma output +# a1 - Counter +.global genPlasma +.type genPlasma, @function +genPlasma: + move $t1, $0 + +.gn_y_loop: move $t0, $0 + +.gn_x_loop: la $v0, plasma_sin1 + sll $v1, $t0, 1 + addu $v1, $v0 + lh $v0, 0($v1) + + la $a2, plasma_sin2 + sll $v1, $t1, 1 + addu $v1, $a2 + lh $v1, 0($v1) + nop + add $v0, $v1 + + add $v1, $t0, $t1 + add $v1, $a1 + divu $v1, 90 + la $a2, plasma_sin3 + mfhi $v1 + + sll $v1, 1 + addu $v1, $a2 + lh $v1, 0($v1) + nop + add $v0, $v1 + + andi $v0, 0xff + + sb $v0, 0($a0) + addu $a0, 1 + + addiu $t0, 1 + blt $t0, 41, .gn_x_loop + nop + + addiu $t1, 1 + blt $t1, 31, .gn_y_loop + nop + + jr $ra + nop + + +# a0 - OT entry +# a1 - Primitive address +# a2 - Plasma map source +.global sortPlasma +.type sortPlasma, @function +sortPlasma: + move $t1, $0 + +.y_loop: + move $t0, $0 + +.x_loop: + lbu $v0, 0($a2) + addiu $a2, 1 + la $a3, plasma_colors + sll $v0, 2 + addu $v0, $a3 + lw $v0, 0($v0) + + lui $v1, 0x3800 + or $v0, $v1 + sw $v0, POLYG4_rgb0($a1) + + + lbu $v0, 0($a2) + nop + sll $v0, 2 + addu $v0, $a3 + lw $v0, 0($v0) + nop + sw $v0, POLYG4_rgb1($a1) + + + lbu $v0, 40($a2) + nop + sll $v0, 2 + addu $v0, $a3 + lw $v0, 0($v0) + nop + sw $v0, POLYG4_rgb2($a1) + + + lbu $v0, 41($a2) + nop + sll $v0, 2 + addu $v0, $a3 + lw $v0, 0($v0) + nop + sw $v0, POLYG4_rgb3($a1) + + + sll $v0, $t0, 4 + andi $v0, 0xffff + sll $v1, $t1, 20 + or $v0, $v1 + sw $v0, POLYG4_xy0($a1) + + sll $v0, $t0, 4 + andi $v0, 0xffff + addi $v0, 16 + sll $v1, $t1, 20 + or $v0, $v1 + sw $v0, POLYG4_xy1($a1) + + sll $v0, $t0, 4 + andi $v0, 0xffff + sll $v1, $t1, 4 + addi $v1, 16 + sll $v1, 16 + or $v0, $v1 + sw $v0, POLYG4_xy2($a1) + + sll $v0, $t0, 4 + andi $v0, 0xffff + addi $v0, 16 + sll $v1, $t1, 4 + addi $v1, 16 + sll $v1, 16 + or $v0, $v1 + sw $v0, POLYG4_xy3($a1) + + .set noat + + lui $v1, 0x0800 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + addiu $a1, POLYG4_len + + + addiu $t0, 1 + blt $t0, 40, .x_loop + nop + + addiu $a2, 1 + addiu $t1, 1 + blt $t1, 30, .y_loop + nop + + + jr $ra + move $v0, $a1 \ No newline at end of file diff --git a/examples/demos/n00bdemo/scrolltext.c b/examples/demos/n00bdemo/scrolltext.c new file mode 100644 index 0000000..e844f21 --- /dev/null +++ b/examples/demos/n00bdemo/scrolltext.c @@ -0,0 +1,136 @@ +const char scroll_text[] = { +"Greetings! Lameguy64 proudly presents a new PlayStation homebrew demo called " +"n00bDEMO and is very much the first time I've released a new demo in years! The " +"last time I released a PlayStation demo was Meido-Demo back in 2013 and boy " +"does this new demo show how far I've gotten good at programming for the " +"PlayStation with graphical effects such as stencil masks and cel-shading " +"never before seen in demos that I'm aware of presented in hi-res mode at 60FPS " +"(50 if PAL). Though there's some flickering issues here and there (though it " +"probably flickers less in PAL mode and none on the PS2 and emulators) which " +"I'll explain the cause of such problems in a bit...\n" + +"Making this demo was pretty challenging (actually, mostly annoying) but " +"mostly for the wrong reasons because this demo is actually not made using " +"the official Sony SDK whatsoever. Yes, I actually put together my own SDK " +"using the GNU GCC toolchain and made the PlayStation GPU and GTE libraries " +"myself mostly in MIPS assembly. I call this SDK project of my own PSn00bSDK " +"and is probably the first homebrewn PlayStation SDK that can actually do 3D " +"graphics with full GTE support that is on-par to the official SDK even in " +"its current work-in-progress state as all other open source SDK examples I've " +"seen only offer very limited or no 3D capabilities whatsoever as with the case " +"of PSXSDK. I used n00b in the naming as I don't want to put pro in the name " +"of my projects knowing that its been used and abused in a lot of shovelware " +"and I wanted something less generic sounding. This SDK project is not exactly " +"professional software after all especially when I get into the issues I've had " +"with this project as of the making of this demo...\n" + +"Currently my SDK mostly offers support for the GPU and GTE but not so much on " +"other hardware features such as SPU, CD (which would be a disgrace not to support), " +"MDEC, controller/memory card and serial I/O. I mostly focused on supporting the " +"GPU and GTE as I feel it was the best way to present a proof of concept that making " +"an open source SDK that is on par to the official SDK should definitely be " +"possible especially when the ins and outs of the PlayStation hardware " +"had since been extensively documented so there's absolutely no excuse for not " +"supporting the hardware features of the console. I'm not certain if I'll continue " +"working on this PSn00bSDK project because I've experienced numerous issues with " +"this project, a lot of which appear to be compiler related (I'm using GCC " +"7.2.0 targetting mipsel-unknown-elf) as doing small code changes would sometimes break " +"or cripple certain parts of a large program that results to slowdown (hence " +"why there's some flicker and I had to omit the Lamelotl artwork in some scenes to " +"try to keep the flicker down) even when the code changes are completely unrelated to the " +"parts that got affected. Issues like these made developing this demo a MASSIVE " +"pain in the butt and it feels like things seem to stall more often than when using the " +"official SDK which also used GCC (2.8.1 to be specific). I'm not entirely sure if " +"they're optimization issues or I'm just pushing the console a little too far :). " +"I feel these issues are detrimental to this project as I don't really want to " +"work with a potentially unstable compiler in my SDK project as that would make " +"creating much larger projects (such as a full game) an even bigger pain " +"in the butt as things would break randomly over small code changes and having to " +"deal with such issues do not conform to my standards. I haven't checked if " +"GCC 8.2.0 has better mipsel support and I've yet to look into clang which is " +"said to support MIPS down to version 1 of the ISA.\n" + +"What I hoped to achieve with PSn00bSDK is to create a 100% free and open " +"source PlayStation SDK that is on-par to the official SDK to make homebrew " +"development for the PS1 much more attractive especially to those interested " +"in developing commercial homebrew for the console without the legal issues " +"surrounding the use of Sony's libraries. But considering the compiler issues " +"I've had and the PS1 community being mostly focussed on emulators and PSIO over " +"actually making homebrew for the console and many of the folks who actually knew how " +"to program for the console especially in low-level have either retired or " +"disappeared, making the feat I wanted to achieve with my SDK project somewhat " +"unlikely I feel. I'll be releasing source code of this demo and " +"the PSn00bSDK libraries on github a week or two as of the release of this " +"demo if things go according to plan on my end and contributions are accepted " +"for those interested to volunteer for this project...\n" + +"You should have noticed by now that there's something inherently missing " +"about this demo. Yes, there's no music in this demo at all. I would've " +"used some CD audio for music but I never got CD playback code working for " +"this demo and I've already made numerous attempts trying to crack the darn " +"thing with no success. At least there's no overused Kevin Macleod music here " +"unlike my last demo which I still wonder why I chose that for the music " +"over rendering out a MOD file into a WAV file and using that instead, man " +"was I stupid back then. Another option would be to use MOD music as I have " +"some SPU support in my SDK but writing my own MOD player would take a lot of " +"time and effort and finishing up this demo has taken long enough I feel as " +"I was originally going to release this demo back in December of 2018. " +"None of the existing MOD players can be used either as Hitmen's player " +"relies on Sony's libraries and is only offered in binary form (because " +"stupid) and PSXSDK's MOD player does all sample mixing in software instead " +"of using the SPU for playing the samples which is abslutely retarded and is " +"definitely not fit for this demo project. If you're watching this demo in " +"video form I've likely dubbed over some music to help keep things " +"interesting as you read this scroll text...\n" + +"There's actually some Scarlet Engine technology featured in this demo " +"namely the SMD model data format which is basically my own implementation " +"of the TMD model data for Scarlet and its drawing functions written in " +"assembly. The implementation featured here uses a newer revision of the SMD " +"model data and the drawing functions are a rewrite but they're still work " +"in progress as it currently does not support the features added in the new " +"revision of the SMD model data format. I haven't worked on Scarlet in awhile " +"as I've somewhat diverted to other things as of late and I've yet to do " +"research on better culling and rendering techniques as my last implementation " +"wasn't really all that good I feel. I plan to implement automated culling " +"using ray scanning when compiling a map and probably a geometry " +"LOD system similar to Spyro's engine. Developing Scarlet has been taking a " +"very long time I know but you have to consider this is being worked on by a " +"single person (who's probably a nobhead) as a hobby with no prior experience " +"in developing a 3D engine and to be honest, working on Scarlet feels a bit " +"too big for a single individual to work on. And in case you're wondering " +"about the apparent name change from Project Scarlet, that's because MS's new " +"Xbox is also codenamed Project Scarlet and I don't really like to have " +"Xbox fanboys looking desperately for videos about MS's Project Scarlet " +"and finding videos about my Project Scarlet instead that would only serve to " +"enrage them or something...\n" + +"Another piece of somewhat advanced technology used in this demo is that " +"all the assets in this demo are all stored in the PS-EXE in LZ77 compressed " +"form using my LZPack libraries to keep PS-EXE size low which speeds up the " +"boot time of this demo. I actually developed the LZPack library for the " +"official SDK in the past but I haven't got around to releasing them but I'm " +"likely going to include them with PSn00bSDK along with the compression/packing " +"tools and it should still work with the official SDK with only minor changes...\n" + +"I think that's pretty much all there is I wanted to say in this demo. I " +"was originally going to release this demo back in December of 2018 but " +"got delayed due to work and other things getting in the way but I hope " +"you enjoyed watching the visuals that were presented in this little " +"proof of concept demo...\n" + +"Greets to nocash NITROYUASH Orion danhans42 Shendo TriMesh " +"inc^lightforce Shadow\n" + +"Programming and most graphical assets in this demo are done by me " +"(Lameguy64). Lamelotl artwork drawn by Lumdrop. Hatkid from A Hat in " +"Time is owned by Gears for Breakfast and the 3D model featured in this " +"demo is made by me...\n" + +"Visit my website at http://lameguy64.tk if you want... " +"Pages are super lightweight with absolutely zero ads! (except joke ads that " +"don't do much other than mock the real ads, in case I've added them in the future)\n" + +"This has been a 2019 Meido-Tek Production!\n" + +}; \ No newline at end of file diff --git a/examples/demos/n00bdemo/smd.h b/examples/demos/n00bdemo/smd.h new file mode 100644 index 0000000..29c2812 --- /dev/null +++ b/examples/demos/n00bdemo/smd.h @@ -0,0 +1,68 @@ +#ifndef _SMD_H +#define _SMD_H + +typedef struct { + int *ot; + short otlen; + unsigned char zdiv,zoff; +} SC_OT; + +typedef struct { + char id[3]; + unsigned char version; + unsigned short flags; + unsigned short n_verts; + unsigned short n_norms; + unsigned short n_prims; + SVECTOR *p_verts; + SVECTOR *p_norms; + void *p_prims; +} SMD; + +typedef struct { + unsigned char type:2; + unsigned char l_type:2; + unsigned char c_type:1; + unsigned char texture:1; + unsigned char blend:2; + unsigned char zoff:4; + unsigned char nocull:1; + unsigned char mask:1; + unsigned char texwin:2; + unsigned char texoff:2; + unsigned char reserved:6; + unsigned char len; +} SMD_PRI_TYPE; + +typedef struct { + SMD_PRI_TYPE prim_id; + unsigned short v0,v1,v2,v3; // Vertex indices + unsigned short n0,n1,n2,n3; // Normal indices + unsigned char r0,g0,b0,code; // RGB0 + unsigned char r1,g1,b1,p0; // RGB1 + unsigned char r2,g2,b2,p1; // RGB2 + unsigned char r3,g3,b3,p2; // RGB3 + unsigned char tu0,tv0; + unsigned char tu1,tv1; + unsigned char tu2,tv2; + unsigned char tu3,tv3; + unsigned short tpage,clut; +} SMD_PRIM; + + +int OpenSMD(void *smd); +SMD_PRIM *ReadSMD(SMD_PRIM *pri); + +void scSetClipRect(int x0, int y0, int x1, int y1); + +SMD *smdInitData(void *data); +void smdSetBaseTPage(unsigned short tpage); + +char *smdSortModel(SC_OT *ot, char* pribuff, SMD *smd); +char *smdSortModelFlat(unsigned int *ot, char* pribuff, SMD *smd); + +void smdSetCelTex(unsigned short tpage, unsigned short clut); +void smdSetCelParam(int udiv, int vdiv, unsigned int col); +char *smdSortModelCel(SC_OT *ot, char* pribuff, SMD *smd); + +#endif \ No newline at end of file diff --git a/examples/demos/n00bdemo/smd.s b/examples/demos/n00bdemo/smd.s new file mode 100644 index 0000000..f9cf2fe --- /dev/null +++ b/examples/demos/n00bdemo/smd.s @@ -0,0 +1,924 @@ +.set noreorder + +.include "gtereg.h" +.include "inline_s.h" +.include "smd_s.h" + + +.section .text + +# Currently does not do header checks +.global smdInitData +.type smdInitData, @function +smdInitData: + + lw $a1, SMD_HEAD_PVERTS($a0) # Initialize header pointers + lw $a2, SMD_HEAD_PNORMS($a0) + lw $a3, SMD_HEAD_PPRIMS($a0) + + addu $a1, $a0 + addu $a2, $a0 + addu $a3, $a0 + + sw $a1, SMD_HEAD_PVERTS($a0) + sw $a2, SMD_HEAD_PNORMS($a0) + sw $a3, SMD_HEAD_PPRIMS($a0) + + jr $ra + move $v0, $a0 + + +.global scSetClipRect +.type scSetClipRect, @function +scSetClipRect: + sll $a1, 16 + or $a0, $a1 + sll $a3, 16 + or $a2, $a3 + la $a1, _sc_clip + sw $a0, 0( $a1 ) + jr $ra + sw $a2, 4( $a1 ) + + +.global smdSetBaseTPage +.type smdSetBaseTPage, @function +smdSetBaseTPage: + la $v0, _smd_tpage_base + jr $ra + sw $a0, 0($v0) + + +.global smdSortModel +.type smdSortModel, @function +smdSortModel: + + # a0 - Pointer SC_OT structure + # a1 - Pointer to next primitive + # a2 - Pointer to SMD data address + # v0 - New pointer of primitive buffer (return) + + addiu $sp, -16 + sw $s0, 0($sp) + sw $s1, 4($sp) + sw $s2, 8($sp) + sw $s3, 12($sp) + + la $v0, _sc_clip + lw $t8, 0($v0) + lw $t9, 4($v0) + + lw $t0, OT_LEN($a0) + lw $a0, OT_ADDR($a0) + lw $t1, SMD_HEAD_PVERTS($a2) + lw $t2, SMD_HEAD_PNORMS($a2) + lw $t3, SMD_HEAD_PPRIMS($a2) + +.sort_loop: + + nop + lw $a3, 0($t3) # Get primitive ID word + move $t4, $t3 + + beqz $a3, .exit # Check if terminator (just zero) + addiu $t4, 4 + + lhu $t5, 0( $t4 ) # Load vertices + lhu $t6, 2( $t4 ) + lhu $t7, 4( $t4 ) + sll $t5, 3 + sll $t6, 3 + sll $t7, 3 + addu $t5, $t1 + addu $t6, $t1 + addu $t7, $t1 + lwc2 C2_VXY0, 0( $t5 ) + lwc2 C2_VZ0 , 4( $t5 ) + lwc2 C2_VXY1, 0( $t6 ) + lwc2 C2_VZ1 , 4( $t6 ) + lwc2 C2_VXY2, 0( $t7 ) + lwc2 C2_VZ2 , 4( $t7 ) + + srl $v1, $a3, 24 # Get primitive size + addu $t3, $v1 # Step main pointer to next primitive + + RTPT + + cfc2 $v0, C2_FLAG # Get GTE flag value + nop + + bltz $v0, .skip_prim # Skip primitive if Z overflow + andi $v0, $a3, 0x3 + + NCLIP # Backface culling + + srl $v1, $a3, 12 + andi $v1, 1 + + bnez $v1, .no_culling + nop + + mfc2 $v1, C2_MAC0 + nop + bltz $v1, .skip_prim + nop + +.no_culling: + + beq $v0, 0x1, .prim_tri # If primitive is a triangle + nop + beq $v0, 0x2, .prim_quad # If primitive is a quad + nop + + b .skip_prim + nop + +## Triangles + +.prim_tri: # Triangle processing + + addiu $t4, 8 # Advance from indices + + AVSZ3 # Calculate average Z + + srl $v0, $t0, 16 # Get Z divisor from OT_LEN value + andi $v0, 0xff + + mfc2 $t5, C2_OTZ # Get AVSZ3 result + + sra $v1, $t0, 24 # Get Z offset from OT_LEN value + + srl $t5, $v0 # Apply divisor and offset + sub $t5, $v1 + + blez $t5, .skip_prim # Skip primitive if less than zero + andi $v1, $t0, 0xffff + bge $t5, $v1, .skip_prim # Skip primitive if greater than OT length + sll $t5, 2 + addu $t5, $a0 # Append OTZ to OT address + + ClipTestTri + + and $v0, $s0, $s1 # v0 & v1 + beqz $v0, .do_draw + and $v0, $s1, $s2 # v1 & v2 + beqz $v0, .do_draw + and $v0, $s2, $s0 # v2 & v0 + beqz $v0, .do_draw + nop + b .skip_prim + nop + +.do_draw: + + + srl $v0, $a3, 2 # Lighting enabled? + andi $v0, 0x3 + bnez $v0, .F3_light + nop + + andi $v0, $a3, 0x10 # Gouraud shaded + bnez $v0, .F3_gouraud + nop + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F3_textured + nop + + lw $v0, 0( $t4 ) # Flat color, no lighting + lui $v1, 0x2000 + or $v0, $v1 + + b .sort_F3_pri + sw $v0, POLYF3_rgbc( $a1 ) + +.F3_gouraud: + + lw $v0, 0($t4) + lw $v1, 4($t4) + .set noat + lui $at, 0x3000 + or $v0, $at + .set at + sw $v0, POLYG3_rgbc0($a1) + lw $v0, 8($t4) + sw $v1, POLYG3_rgbc1($a1) + b .sort_G3_pri + sw $v0, POLYG3_rgbc2($a1) + +.F3_textured: + + lw $v0, 0( $t4 ) # Flat color, no lighting + lui $v1, 0x2400 + or $v0, $v1 + sw $v0, POLYFT3_rgbc( $a1 ) + addiu $t4, 4 + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT3_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT3_uv1( $a1 ) + sh $v0, POLYFT3_uv2( $a1 ) + + lw $v0, 8( $t4 ) # Tpage + CLUT + nop + andi $v1, $v0, 0xffff + sh $v1, POLYFT3_tpage( $a1 ) + srl $v0, 16 + + b .sort_FT3_pri + sh $v0, POLYFT3_clut( $a1 ) + +.F3_light: + + lhu $v0, 0( $t4 ) # Load normal 0 + + srl $v1, $a3, 2 + andi $v1, $v1, 0x3 + + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + beq $v1, 0x2, .F3_light_smt + nop + + lw $v0, 4( $t4 ) + lui $v1, 0x2000 + or $v0, $v1 + mtc2 $v0, C2_RGB + + addiu $t4, 8 + nop + + NCCS + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F3_light_tex + nop + + swc2 C2_RGB2, POLYF3_rgbc( $a1 ) + + b .sort_F3_pri + nop + +.F3_light_tex: + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT3_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT3_uv1( $a1 ) + sh $v0, POLYFT3_uv2( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT3_tpage( $a1 ) + srl $v0, $v1, 16 + sh $v0, POLYFT3_clut( $a1 ) + + mfc2 $v0, C2_RGB2 + lui $v1, 0x2400 + or $v0, $v1 + + b .sort_FT3_pri + sw $v0, POLYFT3_rgbc( $a1 ) + +.F3_light_smt: + + lhu $v0, 2( $t4 ) # Load normals 1 and 2 + lhu $v1, 4( $t4 ) + sll $v0, 3 + sll $v1, 3 + addu $v0, $t2 + addu $v1, $t2 + lwc2 C2_VXY1, 0( $v0 ) + lwc2 C2_VZ1 , 4( $v0 ) + lw $v0, 8( $t4 ) + lwc2 C2_VXY2, 0( $v1 ) + lwc2 C2_VZ2 , 4( $v1 ) + lui $v1, 0x3000 # Load color + or $v0, $v1 + mtc2 $v0, C2_RGB + + addiu $t4, 12 + nop + + NCCT + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F3_light_tex_smt + nop + + swc2 C2_RGB0, POLYG3_rgbc0( $a1 ) + swc2 C2_RGB1, POLYG3_rgbc1( $a1 ) + swc2 C2_RGB2, POLYG3_rgbc2( $a1 ) + + b .sort_G3_pri + nop + +.F3_light_tex_smt: + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYGT3_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYGT3_uv1( $a1 ) + sh $v0, POLYGT3_uv2( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYGT3_tpage( $a1 ) + srl $v0, $v1, 16 + sh $v0, POLYGT3_clut( $a1 ) + + mfc2 $v0, C2_RGB0 + lui $v1, 0x3400 + or $v0, $v1 + + swc2 C2_RGB1, POLYGT3_rgbc1( $a1 ) + swc2 C2_RGB2, POLYGT3_rgbc2( $a1 ) + + b .sort_GT3_pri + sw $v0, POLYGT3_rgbc0( $a1 ) + +.sort_F3_pri: + + swc2 C2_SXY0, POLYF3_xy0($a1) + swc2 C2_SXY1, POLYF3_xy1($a1) + swc2 C2_SXY2, POLYF3_xy2($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYF3_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0500 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYF3_len + +.sort_FT3_pri: + + swc2 C2_SXY0, POLYFT3_xy0( $a1 ) + swc2 C2_SXY1, POLYFT3_xy1( $a1 ) + swc2 C2_SXY2, POLYFT3_xy2( $a1 ) + + .set noat + + lui $v1, 0x0700 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYFT3_len + +.sort_G3_pri: + + swc2 C2_SXY0, POLYG3_xy0( $a1 ) + swc2 C2_SXY1, POLYG3_xy1( $a1 ) + swc2 C2_SXY2, POLYG3_xy2( $a1 ) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYG3_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0700 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYG3_len + +.sort_GT3_pri: + + swc2 C2_SXY0, POLYGT3_xy0( $a1 ) + swc2 C2_SXY1, POLYGT3_xy1( $a1 ) + swc2 C2_SXY2, POLYGT3_xy2( $a1 ) + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYGT3_len + +## Quads + +.prim_quad: # Quad processing + + mfc2 $t6, C2_SXY0 # Retrieve first projected vertex + + lhu $t5, 6( $t4 ) # Project the last vertex + addiu $t4, 8 + sll $t5, 3 + addu $t5, $t1 + lwc2 C2_VXY0, 0( $t5 ) + lwc2 C2_VZ0 , 4( $t5 ) + + nRTPS + + cfc2 $v1, C2_FLAG # Get GTE flag value + + srl $v0, $t0, 16 # Get Z divisor from OT_LEN value + + bltz $v1, .skip_prim + nop + + AVSZ4 + + andi $v0, 0xff + + mfc2 $t5, C2_OTZ + + sra $v1, $t0, 24 # Get Z offset from OT_LEN value + + srl $t5, $v0 # Apply divisor and offset + sub $t5, $v1 + + blez $t5, .skip_prim # Skip primitive if less than zero + andi $v1, $t0, 0xffff + bge $t5, $v1, .skip_prim # Skip primitive if greater than OT length + sll $t5, 2 + addu $t5, $a0 # Append OTZ to OT address + + # no touch: + # a0, a1, a2, a3, t0, t1, t2, t3, t4, t5(ot), t6(sxy0) + + ClipTestQuad + + and $v0, $s0, $s1 # v0 & v1 + beqz $v0, .do_draw_q + and $v0, $s1, $s2 # v1 & v2 + beqz $v0, .do_draw_q + and $v0, $s2, $s3 # v2 & v3 + beqz $v0, .do_draw_q + and $v0, $s3, $s0 # v3 & v0 + beqz $v0, .do_draw_q + and $v0, $s0, $s2 # v0 & v2 + beqz $v0, .do_draw_q + and $v0, $s1, $s3 # v1 & v3 + beqz $v0, .do_draw_q + nop + b .skip_prim + nop + +.do_draw_q: + + srl $v0, $a3, 2 # Lighting enabled? + andi $v0, 0x3 + bnez $v0, .F4_light + nop + + andi $v0, $a3, 0x10 # Gouraud quad + bnez $v0, .F4_gouraud + nop + + andi $v0, $a3, 0x20 # Textured quad + bnez $v0, .F4_textured + nop + + lw $v0, 0($t4) + lui $v1, 0x2800 + or $v0, $v1 + + b .sort_F4_pri + sw $v0, POLYF4_rgbc($a1) + +.F4_gouraud: + + lw $v0, 0($t4) + lw $v1, 4($t4) + .set noat + lui $at, 0x3800 + or $v0, $at + .set at + sw $v0, POLYG4_rgbc0($a1) + lw $v0, 8($t4) + sw $v1, POLYG4_rgbc1($a1) + lw $v1, 12($t4) + sw $v0, POLYG4_rgbc2($a1) + b .sort_G4_pri + sw $v1, POLYG4_rgbc3($a1) + +.F4_textured: + + lw $v0, 0($t4) + lui $v1, 0x2c00 + or $v0, $v1 + sw $v0, POLYFT4_rgbc( $a1 ) + addiu $t4, 4 + + lhu $v0, 0($t4) # Load texture coordinates + lhu $v1, 2($t4) + sh $v0, POLYFT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYFT4_uv2( $a1 ) + sh $v1, POLYFT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT4_tpage( $a1 ) + srl $v0, $v1, 16 + + b .sort_FT4_pri + sh $v0, POLYFT4_clut($a1) + +.F4_light: + + lhu $v0, 0( $t4 ) # Load normal 0 + + srl $v1, $a3, 2 + andi $v1, $v1, 0x3 + + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + beq $v1, 0x2, .F4_light_smt + nop + + lw $v0, 4( $t4 ) + lui $v1, 0x2800 + or $v0, $v1 + mtc2 $v0, C2_RGB + + addiu $t4, 8 + nop + + NCCS + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F4_light_tex + nop + + swc2 C2_RGB2, POLYF4_rgbc( $a1 ) + + b .sort_F4_pri + nop + +.F4_light_tex: + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYFT4_uv2( $a1 ) + sh $v1, POLYFT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT4_tpage( $a1 ) + srl $v0, $v1, 16 + sh $v0, POLYFT4_clut( $a1 ) + + mfc2 $v0, C2_RGB2 + lui $v1, 0x2c00 + or $v0, $v1 + + b .sort_FT4_pri + sw $v0, POLYFT4_rgbc( $a1 ) + +.F4_light_smt: + + lhu $v0, 2( $t4 ) # Load normals 1 and 2 + lhu $v1, 4( $t4 ) + sll $v0, 3 + sll $v1, 3 + addu $v0, $t2 + addu $v1, $t2 + lwc2 C2_VXY1, 0( $v0 ) + lwc2 C2_VZ1 , 4( $v0 ) + lwc2 C2_VXY2, 0( $v1 ) + lwc2 C2_VZ2 , 4( $v1 ) + + lw $v0, 8( $t4 ) + lui $v1, 0x3800 # Load color + or $v0, $v1 + mtc2 $v0, C2_RGB + + nNCCT + + lhu $v0, 6( $t4 ) # Load normal 3 + + addiu $t4, 12 + + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F4_light_tex_smt + nop + + swc2 C2_RGB0, POLYG4_rgbc0( $a1 ) + swc2 C2_RGB1, POLYG4_rgbc1( $a1 ) + swc2 C2_RGB2, POLYG4_rgbc2( $a1 ) + + nNCCS + + swc2 C2_RGB2, POLYG4_rgbc3( $a1 ) + + b .sort_G4_pri + nop + +.F4_light_tex_smt: + + mfc2 $v0, C2_RGB0 + lui $v1, 0x3400 + or $v0, $v1 + sw $v0, POLYGT4_rgbc0( $a1 ) + swc2 C2_RGB1, POLYGT4_rgbc1( $a1 ) + swc2 C2_RGB2, POLYGT4_rgbc2( $a1 ) + + NCCS + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYGT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYGT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYGT4_uv2( $a1 ) + sh $v1, POLYGT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + swc2 C2_RGB2, POLYGT4_rgbc3( $a1 ) + + andi $v0, $v1, 0xffff + sh $v0, POLYGT4_tpage( $a1 ) + srl $v0, $v1, 16 + + b .sort_GT4_pri + sh $v0, POLYGT4_clut( $a1 ) + +.sort_F4_pri: + + sw $t6, POLYF4_xy0($a1) + swc2 C2_SXY0, POLYF4_xy1($a1) + swc2 C2_SXY1, POLYF4_xy2($a1) + swc2 C2_SXY2, POLYF4_xy3($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYF4_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0600 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYF4_len + +.sort_FT4_pri: + + sw $t6, POLYFT4_xy0($a1) + swc2 C2_SXY0, POLYFT4_xy1($a1) + swc2 C2_SXY1, POLYFT4_xy2($a1) + swc2 C2_SXY2, POLYFT4_xy3($a1) + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYFT4_len + +.sort_G4_pri: + + sw $t6, POLYG4_xy0($a1) + swc2 C2_SXY0, POLYG4_xy1($a1) + swc2 C2_SXY1, POLYG4_xy2($a1) + swc2 C2_SXY2, POLYG4_xy3($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYG4_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYG4_len + +.sort_GT4_pri: + + sw $t6, POLYGT4_xy0($a1) + swc2 C2_SXY0, POLYGT4_xy1($a1) + swc2 C2_SXY1, POLYGT4_xy2($a1) + swc2 C2_SXY2, POLYGT4_xy3($a1) + + .set noat + + lui $v1, 0x0c00 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYGT4_len + +.skip_prim: + + b .sort_loop + nop + +.exit: + + lw $s0, 0( $sp ) + lw $s1, 4( $sp ) + lw $s2, 8( $sp ) + lw $s3, 12( $sp ) + addiu $sp, 16 + jr $ra + move $v0, $a1 + + +.comm _smd_tpage_base, 4, 4 + +.comm _sc_clip, 8, 4 diff --git a/examples/demos/n00bdemo/smd_cel.s b/examples/demos/n00bdemo/smd_cel.s new file mode 100644 index 0000000..ece0dd8 --- /dev/null +++ b/examples/demos/n00bdemo/smd_cel.s @@ -0,0 +1,1073 @@ +.set noreorder + +.include "gtereg.h" +.include "inline_s.h" +.include "smd_s.h" + + +.section .text + +.global smdSetCelTex +.type smdSetCelTex, @function +smdSetCelTex: + # a0 - TPage value + # a1 - CLUT value + la $v0, _smd_cel_tpage + andi $a0, 0xffff + sll $a1, 16 + or $a0, $a1 + jr $ra + sw $a0, 0($v0) + + + +.global smdSetCelParam +.type smdSetCelParam, @function +smdSetCelParam: + # a0 - Shading texture U offset + # a1 - Shading texture V offset + # a2 - Shading primitive color + andi $a1, 0xff + sll $a1, 8 + andi $a0, 0xff + or $a0, $a1 + la $v0, _smd_cel_param + sw $a0, 0($v0) + la $v0, _smd_cel_col + lui $v1, 0x0200 + or $a3, $v1 + jr $ra + sw $a2, 0($v0) + + +.global smdSortModelCel +.type smdSortModelCel, @function +smdSortModelCel: + + # a0 - Pointer SC_OT structure + # a1 - Pointer to next primitive + # a2 - Pointer to SMD data address + # v0 - New pointer of primitive buffer (return) + + addiu $sp, -16 + sw $s0, 0($sp) + sw $s1, 4($sp) + sw $s2, 8($sp) + sw $s3, 12($sp) + + la $v0, _sc_clip + lw $t8, 0($v0) + lw $t9, 4($v0) + + lw $t0, OT_LEN($a0) + lw $a0, OT_ADDR($a0) + lw $t1, SMD_HEAD_PVERTS($a2) + lw $t2, SMD_HEAD_PNORMS($a2) + lw $t3, SMD_HEAD_PPRIMS($a2) + +.sort_loop: + + nop + lw $a3, 0($t3) # Get primitive ID word + move $t4, $t3 + + beqz $a3, .exit # Check if terminator (just zero) + addiu $t4, 4 + + lhu $t5, 0( $t4 ) # Load vertices + lhu $t6, 2( $t4 ) + lhu $t7, 4( $t4 ) + sll $t5, 3 + sll $t6, 3 + sll $t7, 3 + addu $t5, $t1 + addu $t6, $t1 + addu $t7, $t1 + lwc2 C2_VXY0, 0( $t5 ) + lwc2 C2_VZ0 , 4( $t5 ) + lwc2 C2_VXY1, 0( $t6 ) + lwc2 C2_VZ1 , 4( $t6 ) + lwc2 C2_VXY2, 0( $t7 ) + lwc2 C2_VZ2 , 4( $t7 ) + + srl $v1, $a3, 24 # Get primitive size + addu $t3, $v1 # Step main pointer to next primitive + + RTPT + + cfc2 $v0, C2_FLAG # Get GTE flag value + nop + + bltz $v0, .skip_prim # Skip primitive if Z overflow + andi $v0, $a3, 0x3 + + NCLIP # Backface culling + + srl $v1, $a3, 12 + andi $v1, 1 + + bnez $v1, .no_culling + nop + + mfc2 $v1, C2_MAC0 + nop + bltz $v1, .skip_prim + nop + +.no_culling: + + beq $v0, 0x1, .prim_tri # If primitive is a triangle + nop + beq $v0, 0x2, .prim_quad # If primitive is a quad + nop + + b .skip_prim + nop + +## Triangles + +.prim_tri: # Triangle processing + + addiu $t4, 8 # Advance from indices + + AVSZ3 # Calculate average Z + + srl $v0, $t0, 16 # Get Z divisor from OT_LEN value + andi $v0, 0xff + + mfc2 $t5, C2_OTZ # Get AVSZ3 result + + sra $v1, $t0, 24 # Get Z offset from OT_LEN value + + srl $t5, $v0 # Apply divisor and offset + sub $t5, $v1 + + blez $t5, .skip_prim # Skip primitive if less than zero + andi $v1, $t0, 0xffff + bge $t5, $v1, .skip_prim # Skip primitive if greater than OT length + sll $t5, 2 + addu $t5, $a0 # Append OTZ to OT address + + ClipTestTri + + and $v0, $s0, $s1 # v0 & v1 + beqz $v0, .do_draw + and $v0, $s1, $s2 # v1 & v2 + beqz $v0, .do_draw + and $v0, $s2, $s0 # v2 & v0 + beqz $v0, .do_draw + nop + b .skip_prim + nop + +.do_draw: + + + srl $v0, $a3, 2 # Lighting enabled? + andi $v0, 0x3 + bnez $v0, .F3_light + nop + + andi $v0, $a3, 0x10 # Gouraud shaded + bnez $v0, .F3_gouraud + nop + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F3_textured + nop + + lw $v0, 0( $t4 ) # Flat color, no lighting + lui $v1, 0x2000 + or $v0, $v1 + + b .sort_F3_pri + sw $v0, POLYF3_rgbc( $a1 ) + +.F3_gouraud: + + lw $v0, 0($t4) + lw $v1, 4($t4) + .set noat + lui $at, 0x3000 + or $v0, $at + .set at + sw $v0, POLYG3_rgbc0($a1) + lw $v0, 8($t4) + sw $v1, POLYG3_rgbc1($a1) + b .sort_G3_pri + sw $v0, POLYG3_rgbc2($a1) + +.F3_textured: + + lw $v0, 0( $t4 ) # Flat color, no lighting + lui $v1, 0x2400 + or $v0, $v1 + sw $v0, POLYFT3_rgbc( $a1 ) + addiu $t4, 4 + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT3_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT3_uv1( $a1 ) + sh $v0, POLYFT3_uv2( $a1 ) + + lw $v0, 8( $t4 ) # Tpage + CLUT + nop + andi $v1, $v0, 0xffff + sh $v1, POLYFT3_tpage( $a1 ) + srl $v0, 16 + + b .sort_FT3_pri + sh $v0, POLYFT3_clut( $a1 ) + +.F3_light: + + lhu $v0, 0( $t4 ) # Load normal 0 + + srl $v1, $a3, 2 + andi $v1, $v1, 0x3 + + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + beq $v1, 0x2, .F3_light_smt + nop + + lw $v0, 4( $t4 ) + lui $v1, 0x2000 + or $v0, $v1 + mtc2 $v0, C2_RGB + + addiu $t4, 8 + nop + + NCCS + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F3_light_tex + nop + + swc2 C2_RGB2, POLYF3_rgbc( $a1 ) + + b .sort_F3_pri + nop + +.F3_light_tex: + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT3_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT3_uv1( $a1 ) + sh $v0, POLYFT3_uv2( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT3_tpage( $a1 ) + srl $v0, $v1, 16 + sh $v0, POLYFT3_clut( $a1 ) + + mfc2 $v0, C2_RGB2 + lui $v1, 0x2400 + or $v0, $v1 + + b .sort_FT3_pri + sw $v0, POLYFT3_rgbc( $a1 ) + +.F3_light_smt: + + lhu $v0, 2($t4) # Load normals 1 and 2 + lhu $v1, 4($t4) + sll $v0, 3 + sll $v1, 3 + addu $v0, $t2 + addu $v1, $t2 + lwc2 C2_VXY1, 0($v0) + lwc2 C2_VZ1 , 4($v0) + #la $v0, _smd_cel_col + #lw $v0, 0($v0) + lwc2 C2_VXY2, 0($v1) + lwc2 C2_VZ2 , 4($v1) + mtc2 $v0, C2_RGB + + swc2 C2_SXY0, POLYFT3_xy0($a1) + swc2 C2_SXY1, POLYFT3_xy1($a1) + swc2 C2_SXY2, POLYFT3_xy2($a1) + + la $v0, _smd_cel_tpage # Load cel shader TPage and CLUT values + lw $v0, 0($v0) + + NCT + + andi $v1, $v0, 0xffff + sh $v1, POLYFT3_tpage($a1) + srl $v1, $v0, 16 + sh $v1, POLYFT3_clut($a1) + + # Usable regs: v0, v1, at, t6, t7 + + .set noat + + la $at, _smd_cel_param # Load cel shader parameters + lhu $at, 0($at) + + mfc2 $t7, C2_RGB0 # Get first shaded color + andi $v1, $at, 0xff # Get U divisor value + andi $t7, 0xffff # Only keep R and G colors + + andi $v0, $t7, 0xff # U0 + srl $v0, $v1 + sb $v0, POLYFT3_uv0($a1) + srl $v0, $t7, 8 # V0 + srl $v1, $at, 8 + srl $v0, $v1 + sb $v0, POLYFT3_uv0+1($a1) + + mfc2 $t7, C2_RGB1 + andi $v1, $at, 0xff + andi $t7, 0xffff + andi $v0, $t7, 0xff # U1 + srl $v0, $v1 + sb $v0, POLYFT3_uv1($a1) + srl $v0, $t7, 8 # V1 + srl $v1, $at, 8 + srl $v0, $v1 + sb $v0, POLYFT3_uv1+1($a1) + + mfc2 $t7, C2_RGB2 + andi $v1, $at, 0xff + andi $t7, 0xffff + andi $v0, $t7, 0xff # U2 + srl $v0, $v1 + sb $v0, POLYFT3_uv2($a1) + srl $v0, $t7, 8 # V2 + srl $v1, $at, 8 + srl $v0, $v1 + sb $v0, POLYFT3_uv2+1($a1) + + la $v0, _smd_cel_col + lw $v0, 0($v0) + lui $v1, 0x2600 + or $v0, $v1 + sw $v0, POLYFT3_rgbc($a1) + + lw $t7, 8($t4) + addiu $t4, 12 + + lui $v1, 0x0700 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $v1, $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $v1 + sw $v0, 0($t5) + + lui $v0, 0x8000 + or $a1, $v0 + addiu $a1, POLYFT3_len + + .set at + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F3_light_tex_smt + nop + + #swc2 C2_RGB0, POLYG3_rgbc0( $a1 ) + #swc2 C2_RGB1, POLYG3_rgbc1( $a1 ) + #swc2 C2_RGB2, POLYG3_rgbc2( $a1 ) + + lui $v0, 0x2000 + or $t7, $v0 + b .sort_F3_pri + sw $t7, POLYF3_rgbc($a1) + +.F3_light_tex_smt: + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT3_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT3_uv1( $a1 ) + sh $v0, POLYFT3_uv2( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT3_tpage( $a1 ) + srl $v0, $v1, 16 + sh $v0, POLYFT3_clut( $a1 ) + + lui $v1, 0x2400 + or $t7, $v1 + + b .sort_FT3_pri + sw $t7, POLYFT3_rgbc( $a1 ) + +.sort_F3_pri: + + swc2 C2_SXY0, POLYF3_xy0($a1) + swc2 C2_SXY1, POLYF3_xy1($a1) + swc2 C2_SXY2, POLYF3_xy2($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYF3_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0500 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYF3_len + +.sort_FT3_pri: + + swc2 C2_SXY0, POLYFT3_xy0( $a1 ) + swc2 C2_SXY1, POLYFT3_xy1( $a1 ) + swc2 C2_SXY2, POLYFT3_xy2( $a1 ) + + .set noat + + lui $v1, 0x0700 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYFT3_len + +.sort_G3_pri: + + swc2 C2_SXY0, POLYG3_xy0( $a1 ) + swc2 C2_SXY1, POLYG3_xy1( $a1 ) + swc2 C2_SXY2, POLYG3_xy2( $a1 ) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYG3_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0700 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYG3_len + +.sort_GT3_pri: + + swc2 C2_SXY0, POLYGT3_xy0( $a1 ) + swc2 C2_SXY1, POLYGT3_xy1( $a1 ) + swc2 C2_SXY2, POLYGT3_xy2( $a1 ) + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYGT3_len + +## Quads + +.prim_quad: # Quad processing + + mfc2 $t6, C2_SXY0 # Retrieve first projected vertex + + lhu $t5, 6( $t4 ) # Project the last vertex + addiu $t4, 8 + sll $t5, 3 + addu $t5, $t1 + lwc2 C2_VXY0, 0( $t5 ) + lwc2 C2_VZ0 , 4( $t5 ) + + nRTPS + + cfc2 $v1, C2_FLAG # Get GTE flag value + + srl $v0, $t0, 16 # Get Z divisor from OT_LEN value + + bltz $v1, .skip_prim + nop + + AVSZ4 + + andi $v0, 0xff + + mfc2 $t5, C2_OTZ + + sra $v1, $t0, 24 # Get Z offset from OT_LEN value + + srl $t5, $v0 # Apply divisor and offset + sub $t5, $v1 + + blez $t5, .skip_prim # Skip primitive if less than zero + andi $v1, $t0, 0xffff + bge $t5, $v1, .skip_prim # Skip primitive if greater than OT length + sll $t5, 2 + addu $t5, $a0 # Append OTZ to OT address + + # no touch: + # a0, a1, a2, a3, t0, t1, t2, t3, t4, t5(ot), t6(sxy0) + + ClipTestQuad + + and $v0, $s0, $s1 # v0 & v1 + beqz $v0, .do_draw_q + and $v0, $s1, $s2 # v1 & v2 + beqz $v0, .do_draw_q + and $v0, $s2, $s3 # v2 & v3 + beqz $v0, .do_draw_q + and $v0, $s3, $s0 # v3 & v0 + beqz $v0, .do_draw_q + and $v0, $s0, $s2 # v0 & v2 + beqz $v0, .do_draw_q + and $v0, $s1, $s3 # v1 & v3 + beqz $v0, .do_draw_q + nop + b .skip_prim + nop + +.do_draw_q: + + srl $v0, $a3, 2 # Lighting enabled? + andi $v0, 0x3 + bnez $v0, .F4_light + nop + + andi $v0, $a3, 0x10 # Gouraud quad + bnez $v0, .F4_gouraud + nop + + andi $v0, $a3, 0x20 # Textured quad + bnez $v0, .F4_textured + nop + + lw $v0, 0($t4) + lui $v1, 0x2800 + or $v0, $v1 + + b .sort_F4_pri + sw $v0, POLYF4_rgbc($a1) + +.F4_gouraud: + + lw $v0, 0($t4) + lw $v1, 4($t4) + .set noat + lui $at, 0x3800 + or $v0, $at + .set at + sw $v0, POLYG4_rgbc0($a1) + lw $v0, 8($t4) + sw $v1, POLYG4_rgbc1($a1) + lw $v1, 12($t4) + sw $v0, POLYG4_rgbc2($a1) + b .sort_G4_pri + sw $v1, POLYG4_rgbc3($a1) + +.F4_textured: + + lw $v0, 0($t4) + lui $v1, 0x2c00 + or $v0, $v1 + sw $v0, POLYFT4_rgbc( $a1 ) + addiu $t4, 4 + + lhu $v0, 0($t4) # Load texture coordinates + lhu $v1, 2($t4) + sh $v0, POLYFT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYFT4_uv2( $a1 ) + sh $v1, POLYFT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT4_tpage( $a1 ) + srl $v0, $v1, 16 + + b .sort_FT4_pri + sh $v0, POLYFT4_clut($a1) + +.F4_light: + + lhu $v0, 0( $t4 ) # Load normal 0 + + srl $v1, $a3, 2 + andi $v1, $v1, 0x3 + + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + beq $v1, 0x2, .F4_light_smt + nop + + lw $v0, 4( $t4 ) + lui $v1, 0x2800 + or $v0, $v1 + mtc2 $v0, C2_RGB + + addiu $t4, 8 + nop + + NCS + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F4_light_tex + nop + + swc2 C2_RGB2, POLYF4_rgbc( $a1 ) + + b .sort_F4_pri + nop + +.F4_light_tex: + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYFT4_uv2( $a1 ) + sh $v1, POLYFT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT4_tpage( $a1 ) + srl $v0, $v1, 16 + sh $v0, POLYFT4_clut( $a1 ) + + mfc2 $v0, C2_RGB2 + lui $v1, 0x2c00 + or $v0, $v1 + + b .sort_FT4_pri + nop + sw $v0, POLYFT4_rgbc( $a1 ) + +.F4_light_smt: + + lhu $v0, 2( $t4 ) # Load normals 1 and 2 + lhu $v1, 4( $t4 ) + sll $v0, 3 + sll $v1, 3 + addu $v0, $t2 + addu $v1, $t2 + lwc2 C2_VXY1, 0( $v0 ) + lwc2 C2_VZ1 , 4( $v0 ) + lwc2 C2_VXY2, 0( $v1 ) + lwc2 C2_VZ2 , 4( $v1 ) + + sw $t6, POLYFT4_xy0($a1) + swc2 C2_SXY0, POLYFT4_xy1($a1) + swc2 C2_SXY1, POLYFT4_xy2($a1) + swc2 C2_SXY2, POLYFT4_xy3($a1) + + la $v0, _smd_cel_tpage # Load cel shader TPage and CLUT values + lw $v0, 0($v0) + + NCT + + andi $v1, $v0, 0xffff + sh $v1, POLYFT4_tpage($a1) + srl $v1, $v0, 16 + sh $v1, POLYFT4_clut($a1) + + # Usable regs: v0, v1, at, t7 + + .set noat + + la $at, _smd_cel_param # Load cel shader parameters + lhu $at, 0($at) + + mfc2 $t7, C2_RGB0 + andi $v1, $at, 0xff # Get U divisor value + andi $t7, 0xffff # Only keep R and G colors + + andi $v0, $t7, 0xff # U0 + srl $v0, $v1 + sb $v0, POLYFT4_uv0($a1) + srl $v0, $t7, 8 # V0 + srl $v1, $at, 8 + srl $v0, $v1 + sb $v0, POLYFT4_uv0+1($a1) + + mfc2 $t7, C2_RGB1 + andi $v1, $at, 0xff + andi $t7, 0xffff + andi $v0, $t7, 0xff # U1 + srl $v0, $v1 + sb $v0, POLYFT4_uv1($a1) + srl $v0, $t7, 8 # V1 + srl $v1, $at, 8 + srl $v0, $v1 + sb $v0, POLYFT4_uv1+1($a1) + + mfc2 $t7, C2_RGB2 + andi $v1, $at, 0xff + andi $t7, 0xffff + andi $v0, $t7, 0xff # U2 + srl $v0, $v1 + sb $v0, POLYFT4_uv2($a1) + srl $v0, $t7, 8 # V2 + srl $v1, $at, 8 + srl $v0, $v1 + sb $v0, POLYFT4_uv2+1($a1) + + la $v0, _smd_cel_col + lw $v0, 0($v0) + lui $v1, 0x2E00 + or $v0, $v1 + sw $v0, POLYFT4_rgbc($a1) + + lw $t7, 8($t4) + + lhu $v0, 6($t4) # Load normal 3 + addiu $t4, 12 + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + nNCS + + mfc2 $s0, C2_RGB2 + andi $v1, $at, 0xff + andi $s0, 0xffff + andi $v0, $s0, 0xff # U3 + srl $v0, $v1 + sb $v0, POLYFT4_uv3($a1) + srl $v0, $s0, 8 # V3 + srl $v1, $at, 8 + srl $v0, $v1 + sb $v0, POLYFT4_uv3+1($a1) + + lui $v1, 0x0900 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $v1, $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $v1 + sw $v0, 0($t5) + + lui $v0, 0x8000 + or $a1, $v0 + addiu $a1, POLYFT4_len + + .set at + + andi $v0, $a3, 0x20 # Textured quad + bnez $v0, .F4_light_tex_smt + nop + + lui $v0, 0x2800 + or $t7, $v0 + b .sort_F4_pri + sw $t7, POLYF4_rgbc($a1) + +.F4_light_tex_smt: + + lhu $v0, 0($t4) # Load texture coordinates + lhu $v1, 2($t4) + sh $v0, POLYFT4_uv0($a1) + lhu $v0, 4($t4) + sh $v1, POLYFT4_uv1($a1) + lhu $v1, 6($t4) + sh $v0, POLYFT4_uv2($a1) + sh $v1, POLYFT4_uv3($a1) + + lw $v1, 8($t4) + + lui $v0, 0x2E00 + or $t7, $v0 + sw $t7, POLYFT4_rgbc($a1) + + andi $v0, $v1, 0xffff + sh $v0, POLYFT4_tpage($a1) + srl $v0, $v1, 16 + + b .sort_FT4_pri + sh $v0, POLYFT4_clut($a1) + +.sort_F4_pri: + + sw $t6, POLYF4_xy0($a1) + swc2 C2_SXY0, POLYF4_xy1($a1) + swc2 C2_SXY1, POLYF4_xy2($a1) + swc2 C2_SXY2, POLYF4_xy3($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYF4_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0600 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYF4_len + +.sort_FT4_pri: + + sw $t6, POLYFT4_xy0($a1) + swc2 C2_SXY0, POLYFT4_xy1($a1) + swc2 C2_SXY1, POLYFT4_xy2($a1) + swc2 C2_SXY2, POLYFT4_xy3($a1) + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYFT4_len + +.sort_G4_pri: + + sw $t6, POLYG4_xy0($a1) + swc2 C2_SXY0, POLYG4_xy1($a1) + swc2 C2_SXY1, POLYG4_xy2($a1) + swc2 C2_SXY2, POLYG4_xy3($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYG4_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYG4_len + +.sort_GT4_pri: + + sw $t6, POLYGT4_xy0($a1) + swc2 C2_SXY0, POLYGT4_xy1($a1) + swc2 C2_SXY1, POLYGT4_xy2($a1) + swc2 C2_SXY2, POLYGT4_xy3($a1) + + .set noat + + lui $v1, 0x0c00 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYGT4_len + +.skip_prim: + + b .sort_loop + nop + +.exit: + + lw $s0, 0( $sp ) + lw $s1, 4( $sp ) + lw $s2, 8( $sp ) + lw $s3, 12( $sp ) + addiu $sp, 16 + jr $ra + move $v0, $a1 + + +.comm _smd_cel_col, 4, 4 # STP shading polygon color +.comm _smd_cel_param, 4, 4 # U divisor, V divisor, shading clip +.comm _smd_cel_tpage, 4, 4 # CEL shader texture page & CLUT + diff --git a/examples/demos/n00bdemo/smd_flat.s b/examples/demos/n00bdemo/smd_flat.s new file mode 100644 index 0000000..0d48c63 --- /dev/null +++ b/examples/demos/n00bdemo/smd_flat.s @@ -0,0 +1,832 @@ +.set noreorder + +.include "gtereg.h" +.include "inline_s.h" +.include "smd_s.h" + + +.section .text + +.global smdSortModelFlat +.type smdSortModelFlat, @function +smdSortModelFlat: + # a0 - Pointer SC_OT structure + # a1 - Pointer to next primitive + # a2 - Pointer to SMD data address + # v0 - New pointer of primitive buffer (return) + + addiu $sp, -16 + sw $s0, 0( $sp ) + sw $s1, 4( $sp ) + sw $s2, 8( $sp ) + sw $s3, 12( $sp ) + + la $v0, _sc_clip + lw $t8, 0($v0) + lw $t9, 4($v0) + + lw $t1, SMD_HEAD_PVERTS( $a2 ) + lw $t2, SMD_HEAD_PNORMS( $a2 ) + lw $t3, SMD_HEAD_PPRIMS( $a2 ) + +.sort_loop: + + nop + lw $a3, 0($t3) # Get primitive ID word + move $t4, $t3 + + beqz $a3, .exit # Check if terminator (just zero) + addiu $t4, 4 + + lhu $t5, 0( $t4 ) # Load vertices + lhu $t6, 2( $t4 ) + lhu $t7, 4( $t4 ) + sll $t5, 3 + sll $t6, 3 + sll $t7, 3 + addu $t5, $t1 + addu $t6, $t1 + addu $t7, $t1 + lwc2 C2_VXY0, 0( $t5 ) + lwc2 C2_VZ0 , 4( $t5 ) + lwc2 C2_VXY1, 0( $t6 ) + lwc2 C2_VZ1 , 4( $t6 ) + lwc2 C2_VXY2, 0( $t7 ) + lwc2 C2_VZ2 , 4( $t7 ) + + srl $v1, $a3, 24 # Get primitive size + addu $t3, $v1 # Step main pointer to next primitive + + RTPT + + cfc2 $v0, C2_FLAG # Get GTE flag value + nop + + bltz $v0, .skip_prim # Skip primitive if Z overflow + nop + + #NCLIP # Backface culling + + #mfc2 $v1, C2_MAC0 + + andi $v0, $a3, 0x3 + + #bltz $v1, .skip_prim + #nop + + beq $v0, 0x1, .prim_tri # If primitive is a triangle + nop + beq $v0, 0x2, .prim_quad # If primitive is a quad + nop + + b .skip_prim + nop + +## Triangles + +.prim_tri: # Triangle processing + + addiu $t4, 8 # Advance from indices + + #AVSZ3 # Calculate average Z + + ClipTestTri + + and $v0, $s0, $s1 # v0 & v1 + beqz $v0, .do_draw + and $v0, $s1, $s2 # v1 & v2 + beqz $v0, .do_draw + and $v0, $s2, $s0 # v2 & v0 + beqz $v0, .do_draw + nop + b .skip_prim + nop + +.do_draw: + + #srl $v0, $a3, 2 # Lighting enabled? + #andi $v0, 0x3 + #bnez $v0, .F3_light + #nop + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F3_textured + nop + + andi $v0, $a3, 0x10 # Gouraud shaded + bnez $v0, .F3_gouraud + nop + + lw $v0, 0( $t4 ) # Flat color, no lighting + lui $v1, 0x2000 + or $v0, $v1 + + b .sort_F3_pri + sw $v0, POLYF3_rgbc( $a1 ) + +.F3_textured: + + lw $v0, 0( $t4 ) # Flat color, no lighting + lui $v1, 0x2400 + or $v0, $v1 + sw $v0, POLYFT3_rgbc( $a1 ) + addiu $t4, 4 + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT3_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT3_uv1( $a1 ) + sh $v0, POLYFT3_uv2( $a1 ) + + lw $v0, 8( $t4 ) # Tpage + CLUT + nop + andi $v1, $v0, 0xffff + sh $v1, POLYFT3_tpage( $a1 ) + srl $v0, 16 + + b .sort_FT3_pri + sh $v0, POLYFT3_clut( $a1 ) + +.F3_gouraud: + lw $v0, 0($t4) + lw $v1, 4($t4) + .set noat + lui $at, 0x3000 + or $v0, $at + .set at + sw $v0, POLYG3_rgbc0($a1) + lw $v0, 8($t4) + sw $v1, POLYG3_rgbc1($a1) + b .sort_G3_pri + sw $v0, POLYG3_rgbc2($a1) + +#.F3_light: + + #lhu $v0, 0( $t4 ) # Load normal 0 + + #srl $v1, $a3, 2 + #andi $v1, $v1, 0x3 + + #sll $v0, 3 + #addu $v0, $t2 + #lwc2 C2_VXY0, 0( $v0 ) + #lwc2 C2_VZ0 , 4( $v0 ) + + #beq $v1, 0x2, .F3_light_smt + #nop + + #lw $v0, 4( $t4 ) + #lui $v1, 0x2000 + #or $v0, $v1 + #mtc2 $v0, C2_RGB + + #addiu $t4, 8 + #nop + + #NCCS + + #andi $v0, $a3, 0x20 # Textured triangle + #bnez $v0, .F3_light_tex + #nop + + #swc2 C2_RGB2, POLYF3_rgbc( $a1 ) + + #b .sort_F3_pri + #nop + +#.F3_light_tex: + + #lhu $v0, 0( $t4 ) # Load texture coordinates + #lhu $v1, 2( $t4 ) + #sh $v0, POLYFT3_uv0( $a1 ) + #lhu $v0, 4( $t4 ) + #sh $v1, POLYFT3_uv1( $a1 ) + #sh $v0, POLYFT3_uv2( $a1 ) + + #lw $v1, 8( $t4 ) + #nop + #andi $v0, $v1, 0xffff + #sh $v0, POLYFT3_tpage( $a1 ) + #srl $v0, $v1, 16 + #sh $v0, POLYFT3_clut( $a1 ) + + #mfc2 $v0, C2_RGB2 + #lui $v1, 0x2400 + #or $v0, $v1 + + #b .sort_FT3_pri + #sw $v0, POLYFT3_rgbc( $a1 ) + +#.F3_light_smt: + + #lhu $v0, 2( $t4 ) # Load normals 1 and 2 + #lhu $v1, 4( $t4 ) + #sll $v0, 3 + #sll $v1, 3 + #addu $v0, $t2 + #addu $v1, $t2 + #lwc2 C2_VXY1, 0( $v0 ) + #lwc2 C2_VZ1 , 4( $v0 ) + #lw $v0, 8( $t4 ) + #lwc2 C2_VXY2, 0( $v1 ) + #lwc2 C2_VZ2 , 4( $v1 ) + #lui $v1, 0x3000 # Load color + #or $v0, $v1 + #mtc2 $v0, C2_RGB + + #addiu $t4, 12 + #nop + + #NCCT + + #andi $v0, $a3, 0x20 # Textured triangle + #bnez $v0, .F3_light_tex_smt + #nop + + #swc2 C2_RGB0, POLYG3_rgbc0( $a1 ) + #swc2 C2_RGB1, POLYG3_rgbc1( $a1 ) + #swc2 C2_RGB2, POLYG3_rgbc2( $a1 ) + + #b .sort_G3_pri + #nop + +# .F3_light_tex_smt: + + # lhu $v0, 0( $t4 ) # Load texture coordinates + # lhu $v1, 2( $t4 ) + # sh $v0, POLYGT3_uv0( $a1 ) + # lhu $v0, 4( $t4 ) + # sh $v1, POLYGT3_uv1( $a1 ) + # sh $v0, POLYGT3_uv2( $a1 ) + + # lw $v1, 8( $t4 ) + # nop + # andi $v0, $v1, 0xffff + # sh $v0, POLYGT3_tpage( $a1 ) + # srl $v0, $v1, 16 + # sh $v0, POLYGT3_clut( $a1 ) + + # mfc2 $v0, C2_RGB0 + # lui $v1, 0x3400 + # or $v0, $v1 + + # swc2 C2_RGB1, POLYGT3_rgbc1( $a1 ) + # swc2 C2_RGB2, POLYGT3_rgbc2( $a1 ) + + # b .sort_GT3_pri + # sw $v0, POLYGT3_rgbc0( $a1 ) + +.sort_F3_pri: + + swc2 C2_SXY0, POLYF3_xy0($a1) + swc2 C2_SXY1, POLYF3_xy1($a1) + swc2 C2_SXY2, POLYF3_xy2($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYF3_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0500 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYF3_len + +.sort_FT3_pri: + + swc2 C2_SXY0, POLYFT3_xy0( $a1 ) + swc2 C2_SXY1, POLYFT3_xy1( $a1 ) + swc2 C2_SXY2, POLYFT3_xy2( $a1 ) + + .set noat + + lui $v1, 0x0700 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYFT3_len + +.sort_G3_pri: + + swc2 C2_SXY0, POLYG3_xy0( $a1 ) + swc2 C2_SXY1, POLYG3_xy1( $a1 ) + swc2 C2_SXY2, POLYG3_xy2( $a1 ) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYG3_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0700 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYG3_len + +.sort_GT3_pri: + + swc2 C2_SXY0, POLYGT3_xy0( $a1 ) + swc2 C2_SXY1, POLYGT3_xy1( $a1 ) + swc2 C2_SXY2, POLYGT3_xy2( $a1 ) + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYGT3_len + +## Quads + +.prim_quad: # Quad processing + + mfc2 $t6, C2_SXY0 # Retrieve first projected vertex + + lhu $t5, 6( $t4 ) # Project the last vertex + addiu $t4, 8 + sll $t5, 3 + addu $t5, $t1 + lwc2 C2_VXY0, 0( $t5 ) + lwc2 C2_VZ0 , 4( $t5 ) + + nRTPS + + cfc2 $v1, C2_FLAG # Get GTE flag value + + nop + + bltz $v1, .skip_prim + nop + + ClipTestQuad + + and $v0, $s0, $s1 # v0 & v1 + beqz $v0, .do_draw_q + and $v0, $s1, $s2 # v1 & v2 + beqz $v0, .do_draw_q + and $v0, $s2, $s3 # v2 & v3 + beqz $v0, .do_draw_q + and $v0, $s3, $s0 # v3 & v0 + beqz $v0, .do_draw_q + and $v0, $s0, $s2 # v0 & v2 + beqz $v0, .do_draw_q + and $v0, $s1, $s3 # v1 & v3 + beqz $v0, .do_draw_q + nop + b .skip_prim + nop + +.do_draw_q: + + srl $v0, $a3, 2 # Lighting enabled? + andi $v0, 0x3 + bnez $v0, .F4_light + nop + + andi $v0, $a3, 0x10 # Gouraud quad + bnez $v0, .F4_gouraud + nop + + andi $v0, $a3, 0x20 # Textured quad + bnez $v0, .F4_textured + nop + + lw $v0, 0($t4) + lui $v1, 0x2800 + or $v0, $v1 + + b .sort_F4_pri + sw $v0, POLYF4_rgbc($a1) + +.F4_textured: + + lw $v0, 0($t4) + lui $v1, 0x2c00 + or $v0, $v1 + sw $v0, POLYFT4_rgbc( $a1 ) + addiu $t4, 4 + + lhu $v0, 0($t4) # Load texture coordinates + lhu $v1, 2($t4) + sh $v0, POLYFT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYFT4_uv2( $a1 ) + sh $v1, POLYFT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT4_tpage( $a1 ) + srl $v0, $v1, 16 + + b .sort_FT4_pri + sh $v0, POLYFT4_clut($a1) + +.F4_gouraud: + + lw $v0, 0($t4) + lw $v1, 4($t4) + .set noat + lui $at, 0x3800 + or $v0, $at + .set at + sw $v0, POLYG4_rgbc0($a1) + lw $v0, 8($t4) + sw $v1, POLYG4_rgbc1($a1) + lw $v1, 12($t4) + sw $v0, POLYG4_rgbc2($a1) + b .sort_G4_pri + sw $v1, POLYG4_rgbc3($a1) + + +.F4_light: + + lhu $v0, 0( $t4 ) # Load normal 0 + + srl $v1, $a3, 2 + andi $v1, $v1, 0x3 + + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + beq $v1, 0x2, .F4_light_smt + nop + + lw $v0, 4( $t4 ) + lui $v1, 0x2800 + or $v0, $v1 + mtc2 $v0, C2_RGB + + addiu $t4, 8 + nop + + NCCS + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F4_light_tex + nop + + swc2 C2_RGB2, POLYF4_rgbc( $a1 ) + + b .sort_F4_pri + nop + +.F4_light_tex: + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYFT4_uv2( $a1 ) + sh $v1, POLYFT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT4_tpage( $a1 ) + srl $v0, $v1, 16 + sh $v0, POLYFT4_clut( $a1 ) + + mfc2 $v0, C2_RGB2 + lui $v1, 0x2c00 + or $v0, $v1 + + b .sort_FT4_pri + sw $v0, POLYFT4_rgbc( $a1 ) + +.F4_light_smt: + + lhu $v0, 2( $t4 ) # Load normals 1 and 2 + lhu $v1, 4( $t4 ) + sll $v0, 3 + sll $v1, 3 + addu $v0, $t2 + addu $v1, $t2 + lwc2 C2_VXY1, 0( $v0 ) + lwc2 C2_VZ1 , 4( $v0 ) + lwc2 C2_VXY2, 0( $v1 ) + lwc2 C2_VZ2 , 4( $v1 ) + + lw $v0, 8( $t4 ) + lui $v1, 0x3800 # Load color + or $v0, $v1 + mtc2 $v0, C2_RGB + + nNCCT + + lhu $v0, 6( $t4 ) # Load normal 3 + + addiu $t4, 12 + + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F4_light_tex_smt + nop + + swc2 C2_RGB0, POLYG4_rgbc0( $a1 ) + swc2 C2_RGB1, POLYG4_rgbc1( $a1 ) + swc2 C2_RGB2, POLYG4_rgbc2( $a1 ) + + nNCCS + + swc2 C2_RGB2, POLYG4_rgbc3( $a1 ) + + b .sort_G4_pri + nop + +.F4_light_tex_smt: + + mfc2 $v0, C2_RGB0 + lui $v1, 0x3400 + or $v0, $v1 + sw $v0, POLYGT4_rgbc0( $a1 ) + swc2 C2_RGB1, POLYGT4_rgbc1( $a1 ) + swc2 C2_RGB2, POLYGT4_rgbc2( $a1 ) + + NCCS + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYGT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYGT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYGT4_uv2( $a1 ) + sh $v1, POLYGT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + swc2 C2_RGB2, POLYGT4_rgbc3( $a1 ) + + andi $v0, $v1, 0xffff + sh $v0, POLYGT4_tpage( $a1 ) + srl $v0, $v1, 16 + + b .sort_GT4_pri + sh $v0, POLYGT4_clut( $a1 ) + +.sort_F4_pri: + + sw $t6, POLYF4_xy0($a1) + swc2 C2_SXY0, POLYF4_xy1($a1) + swc2 C2_SXY1, POLYF4_xy2($a1) + swc2 C2_SXY2, POLYF4_xy3($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYF4_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0600 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYF4_len + +.sort_FT4_pri: + + sw $t6, POLYFT4_xy0($a1) + swc2 C2_SXY0, POLYFT4_xy1($a1) + swc2 C2_SXY1, POLYFT4_xy2($a1) + swc2 C2_SXY2, POLYFT4_xy3($a1) + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYFT4_len + +.sort_G4_pri: + + sw $t6, POLYG4_xy0($a1) + swc2 C2_SXY0, POLYG4_xy1($a1) + swc2 C2_SXY1, POLYG4_xy2($a1) + swc2 C2_SXY2, POLYG4_xy3($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYG4_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYG4_len + +.sort_GT4_pri: + + sw $t6, POLYGT4_xy0($a1) + swc2 C2_SXY0, POLYGT4_xy1($a1) + swc2 C2_SXY1, POLYGT4_xy2($a1) + swc2 C2_SXY2, POLYGT4_xy3($a1) + + .set noat + + lui $v1, 0x0c00 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYGT4_len + +.skip_prim: + + b .sort_loop + nop + +.exit: + + lw $s0, 0( $sp ) + lw $s1, 4( $sp ) + lw $s2, 8( $sp ) + lw $s3, 12( $sp ) + addiu $sp, 16 + jr $ra + move $v0, $a1 + \ No newline at end of file diff --git a/examples/demos/n00bdemo/smd_s.h b/examples/demos/n00bdemo/smd_s.h new file mode 100644 index 0000000..4dca4dd --- /dev/null +++ b/examples/demos/n00bdemo/smd_s.h @@ -0,0 +1,336 @@ +.set OT_ADDR, 0 +.set OT_LEN, 4 +.set OT_ZDIV, 8 +.set OT_ZOFF, 10 + +.set SMD_HEAD_ID, 0 +.set SMD_HEAD_FLAG, 4 +.set SMD_HEAD_NVERTS, 6 +.set SMD_HEAD_NNORMS, 8 +.set SMD_HEAD_NPRIMS, 10 +.set SMD_HEAD_PVERTS, 12 +.set SMD_HEAD_PNORMS, 16 +.set SMD_HEAD_PPRIMS, 20 +.set SMD_HEAD_SIZE, 24 + +.set POLYF3_tag, 0 +.set POLYF3_tpage, 4 +.set POLYF3_rgbc, 8 +.set POLYF3_xy0, 12 +.set POLYF3_xy1, 16 +.set POLYF3_xy2, 20 +.set POLYF3_len, 24 + +.set POLYFT3_tag, 0 +.set POLYFT3_rgbc, 4 +.set POLYFT3_xy0, 8 +.set POLYFT3_uv0, 12 +.set POLYFT3_clut, 14 +.set POLYFT3_xy1, 16 +.set POLYFT3_uv1, 20 +.set POLYFT3_tpage, 22 +.set POLYFT3_xy2, 24 +.set POLYFT3_uv2, 28 +.set POLYFT3_pad, 30 +.set POLYFT3_len, 32 + +.set POLYG3_tag, 0 +.set POLYG3_tpage, 4 +.set POLYG3_rgbc0, 8 +.set POLYG3_xy0, 12 +.set POLYG3_rgbc1, 16 +.set POLYG3_xy1, 20 +.set POLYG3_rgbc2, 24 +.set POLYG3_xy2, 28 +.set POLYG3_len, 32 + +.set POLYGT3_tag, 0 +.set POLYGT3_rgbc0, 4 +.set POLYGT3_xy0, 8 +.set POLYGT3_uv0, 12 +.set POLYGT3_clut, 14 +.set POLYGT3_rgbc1, 16 +.set POLYGT3_xy1, 20 +.set POLYGT3_uv1, 24 +.set POLYGT3_tpage, 26 +.set POLYGT3_rgbc2, 28 +.set POLYGT3_xy2, 32 +.set POLYGT3_uv2, 36 +.set POLYGT3_pad, 38 +.set POLYGT3_len, 40 + +.set POLYF4_tag, 0 +.set POLYF4_tpage, 4 +.set POLYF4_rgbc, 8 +.set POLYF4_xy0, 12 +.set POLYF4_xy1, 16 +.set POLYF4_xy2, 20 +.set POLYF4_xy3, 24 +.set POLYF4_len, 28 + +.set POLYFT4_tag, 0 +.set POLYFT4_rgbc, 4 +.set POLYFT4_xy0, 8 +.set POLYFT4_uv0, 12 +.set POLYFT4_clut, 14 +.set POLYFT4_xy1, 16 +.set POLYFT4_uv1, 20 +.set POLYFT4_tpage, 22 +.set POLYFT4_xy2, 24 +.set POLYFT4_uv2, 28 +.set POLYFT4_pad0, 30 +.set POLYFT4_xy3, 32 +.set POLYFT4_uv3, 36 +.set POLYFT4_pad1, 38 +.set POLYFT4_len, 40 + +.set POLYG4_tag, 0 +.set POLYG4_tpage, 4 +.set POLYG4_rgbc0, 8 +.set POLYG4_xy0, 12 +.set POLYG4_rgbc1, 16 +.set POLYG4_xy1, 20 +.set POLYG4_rgbc2, 24 +.set POLYG4_xy2, 28 +.set POLYG4_rgbc3, 32 +.set POLYG4_xy3, 36 +.set POLYG4_len, 40 + +.set POLYGT4_tag, 0 +.set POLYGT4_rgbc0, 4 +.set POLYGT4_xy0, 8 +.set POLYGT4_uv0, 12 +.set POLYGT4_clut, 14 +.set POLYGT4_rgbc1, 16 +.set POLYGT4_xy1, 20 +.set POLYGT4_uv1, 24 +.set POLYGT4_tpage, 26 +.set POLYGT4_rgbc2, 28 +.set POLYGT4_xy2, 32 +.set POLYGT4_uv2, 36 +.set POLYGT4_pad0, 38 +.set POLYGT4_rgbc3, 40 +.set POLYGT4_xy3, 44 +.set POLYGT4_uv3, 48 +.set POLYGT4_pad1, 50 +.set POLYGT4_len, 52 + +.set CLIP_LEFT, 1 +.set CLIP_RIGHT, 2 +.set CLIP_TOP, 4 +.set CLIP_BOTTOM, 8 + + +# Clip routine macros, based on Cohen-Sutherland line clipping algorithm +# but only with the off-screen dectection logic extended for polygons + +.macro ClipTestTri + + # X0 clip test + mfc2 $t7, C2_SXY0 + sll $v1, $t8, 16 + sra $v1, 16 + sll $v0, $t7, 16 + sra $v0, 16 + bge $v0, $v1, .no_clip_l_x0 + move $s0, $0 + ori $s0, CLIP_LEFT +.no_clip_l_x0: + sll $v1, $t9, 16 + sra $v1, 16 + ble $v0, $v1, .no_clip_r_x0 + nop + ori $s0, CLIP_RIGHT +.no_clip_r_x0: + # Y0 clip test + sra $v0, $t7, 16 + sra $v1, $t8, 16 + bge $v0, $v1, .no_clip_t_y0 + nop + ori $s0, CLIP_TOP +.no_clip_t_y0: + sra $v1, $t9, 16 + ble $v0, $v1, .no_clip_b_y0 + nop + ori $s0, CLIP_BOTTOM +.no_clip_b_y0: + + # X1 clip test + mfc2 $t7, C2_SXY1 + sll $v1, $t8, 16 + sra $v1, 16 + sll $v0, $t7, 16 + sra $v0, 16 + bge $v0, $v1, .no_clip_l_x1 + move $s1, $0 + ori $s1, CLIP_LEFT +.no_clip_l_x1: + sll $v1, $t9, 16 + sra $v1, 16 + ble $v0, $v1, .no_clip_r_x1 + nop + ori $s1, CLIP_RIGHT +.no_clip_r_x1: + # Y1 clip test + sra $v0, $t7, 16 + sra $v1, $t8, 16 + bge $v0, $v1, .no_clip_t_y1 + nop + ori $s1, CLIP_TOP +.no_clip_t_y1: + sra $v1, $t9, 16 + ble $v0, $v1, .no_clip_b_y1 + nop + ori $s1, CLIP_BOTTOM +.no_clip_b_y1: + + # X2 clip test + mfc2 $t7, C2_SXY2 + sll $v1, $t8, 16 + sra $v1, 16 + sll $v0, $t7, 16 + sra $v0, 16 + bge $v0, $v1, .no_clip_l_x2 + move $s2, $0 + ori $s2, CLIP_LEFT +.no_clip_l_x2: + sll $v1, $t9, 16 + sra $v1, 16 + ble $v0, $v1, .no_clip_r_x2 + nop + ori $s2, CLIP_RIGHT +.no_clip_r_x2: + # Y2 clip test + sra $v0, $t7, 16 + sra $v1, $t8, 16 + bge $v0, $v1, .no_clip_t_y2 + nop + ori $s2, CLIP_TOP +.no_clip_t_y2: + sra $v1, $t9, 16 + ble $v0, $v1, .no_clip_b_y2 + nop + ori $s2, CLIP_BOTTOM +.no_clip_b_y2: + +.endm + + +.macro ClipTestQuad + + # X0 clip test + sll $v0, $t6, 16 + sra $v0, 16 + sll $v1, $t8, 16 + sra $v1, 16 + bge $v0, $v1, .no_clip_l_x0_q + move $s0, $0 + ori $s0, CLIP_LEFT +.no_clip_l_x0_q: + sll $v1, $t9, 16 + sra $v1, 16 + ble $v0, $v1, .no_clip_r_x0_q + nop + ori $s0, CLIP_RIGHT +.no_clip_r_x0_q: + # Y0 clip test + sra $v0, $t6, 16 + sra $v1, $t8, 16 + bge $v0, $v1, .no_clip_t_y0_q + nop + ori $s0, CLIP_TOP +.no_clip_t_y0_q: + sra $v1, $t9, 16 + ble $v0, $v1, .no_clip_b_y0_q + nop + ori $s0, CLIP_BOTTOM +.no_clip_b_y0_q: + + # X1 clip test + mfc2 $t7, C2_SXY0 + sll $v1, $t8, 16 + sra $v1, 16 + sll $v0, $t7, 16 + sra $v0, 16 + bge $v0, $v1, .no_clip_l_x1_q + move $s1, $0 + ori $s1, CLIP_LEFT +.no_clip_l_x1_q: + sll $v1, $t9, 16 + sra $v1, 16 + ble $v0, $v1, .no_clip_r_x1_q + nop + ori $s1, CLIP_RIGHT +.no_clip_r_x1_q: + # Y1 clip test + sra $v0, $t7, 16 + sra $v1, $t8, 16 + bge $v0, $v1, .no_clip_t_y1_q + nop + ori $s1, CLIP_TOP +.no_clip_t_y1_q: + sra $v1, $t9, 16 + ble $v0, $v1, .no_clip_b_y1_q + nop + ori $s1, CLIP_BOTTOM +.no_clip_b_y1_q: + + # X2 clip test + mfc2 $t7, C2_SXY1 + sll $v1, $t8, 16 + sra $v1, 16 + sll $v0, $t7, 16 + sra $v0, 16 + bge $v0, $v1, .no_clip_l_x2_q + move $s2, $0 + ori $s2, CLIP_LEFT +.no_clip_l_x2_q: + sll $v1, $t9, 16 + sra $v1, 16 + ble $v0, $v1, .no_clip_r_x2_q + nop + ori $s2, CLIP_RIGHT +.no_clip_r_x2_q: + # Y2 clip test + sra $v0, $t7, 16 + sra $v1, $t8, 16 + bge $v0, $v1, .no_clip_t_y2_q + nop + ori $s2, CLIP_TOP +.no_clip_t_y2_q: + sra $v1, $t9, 16 + ble $v0, $v1, .no_clip_b_y2_q + nop + ori $s2, CLIP_BOTTOM +.no_clip_b_y2_q: + + # X3 clip test + mfc2 $t7, C2_SXY2 + sll $v1, $t8, 16 + sra $v1, 16 + sll $v0, $t7, 16 + sra $v0, 16 + bge $v0, $v1, .no_clip_l_x3_q + move $s3, $0 + ori $s3, CLIP_LEFT +.no_clip_l_x3_q: + sll $v1, $t9, 16 + sra $v1, 16 + ble $v0, $v1, .no_clip_r_x3_q + nop + ori $s3, CLIP_RIGHT +.no_clip_r_x3_q: + # Y4 clip test + sra $v0, $t7, 16 + sra $v1, $t8, 16 + bge $v0, $v1, .no_clip_t_y3_q + nop + ori $s3, CLIP_TOP +.no_clip_t_y3_q: + sra $v1, $t9, 16 + ble $v0, $v1, .no_clip_b_y3_q + nop + ori $s3, CLIP_BOTTOM +.no_clip_b_y3_q: + +.endm diff --git a/examples/demos/n00bdemo/smdparser.s b/examples/demos/n00bdemo/smdparser.s new file mode 100644 index 0000000..379690f --- /dev/null +++ b/examples/demos/n00bdemo/smdparser.s @@ -0,0 +1,129 @@ +.set noreorder + +.include "smd_s.h" + +.set SMD_PRI_ID, 0 +.set SMD_PRI_v0, 4 +.set SMD_PRI_v1, 6 +.set SMD_PRI_v2, 8 +.set SMD_PRI_v3, 10 +.set SMD_PRI_n0, 12 +.set SMD_PRI_n1, 14 +.set SMD_PRI_n2, 16 +.set SMD_PRI_n3, 18 +.set SMD_PRI_rgbc0, 20 +.set SMD_PRI_rgbc1, 24 +.set SMD_PRI_rgbc2, 28 +.set SMD_PRI_rgbc3, 32 +.set SMD_PRI_tuv0, 36 +.set SMD_PRI_tuv1, 38 +.set SMD_PRI_tuv2, 40 +.set SMD_PRI_tuv3, 42 +.set SMD_PRI_tpage, 44 +.set SMD_PRI_clut, 46 + +.section .text + + +.comm _smd_parse_addr, 4, 4 + + +.global OpenSMD +.type OpenSMD, @function +OpenSMD: + lw $v0, SMD_HEAD_ID($a0) + li $v1, 0x01444d53 + + bne $v0, $v1, .not_smd + nop + + lw $v0, SMD_HEAD_PPRIMS($a0) + la $v1, _smd_parse_addr + sw $v0, 0($v1) + + jr $ra + lhu $v0, SMD_HEAD_NPRIMS($a0) + +.not_smd: + jr $ra + move $v0, $0 + + +.global ReadSMD +.type ReadSMD, @function +ReadSMD: + + la $v0, _smd_parse_addr + lw $v0, 0($v0) + nop + + lw $a2, 0($v0) # Load primitive ID + addiu $a1, $v0, 4 + + sw $a2, SMD_PRI_ID($a0) + + beqz $a2, $end_prim + nop + + srl $v1, $a2, 24 # Get primitive size + addu $v0, $v1 + la $v1, _smd_parse_addr + sw $v0, 0($v1) + + lw $v0, 0($a1) # Copy vertex coords + lw $v1, 4($a1) + sw $v0, SMD_PRI_v0($a0) + sw $v1, SMD_PRI_v2($a0) + addiu $a1, 8 + + srl $v0, $a2, 2 # Lighting enabled? + andi $v0, 0x3 + bnez $v0, $light + nop + + b $no_light + nop + +$light: + srl $v1, $a2, 2 + lw $v0, 0($a1) # Copy vertex coords + andi $v1, 0x3 + sw $v0, SMD_PRI_n0($a0) + + bne $v1, 0x2, $light_flat + addiu $a1, 4 + + lw $v1, 0($a1) + addiu $a1, 4 + sw $v1, SMD_PRI_n2($a0) + +$light_flat: +$no_light: + + lw $v0, 0($a1) + nop + sw $v0, SMD_PRI_rgbc0($a0) + addiu $a1, 4 + + srl $v0, $a2, 5 + andi $v0, 0x1 + beqz $v0, $not_textured + nop + + lw $v0, 0($a1) + lw $v1, 4($a1) + sw $v0, SMD_PRI_tuv0($a0) + lw $v0, 8($a1) + sw $v1, SMD_PRI_tuv2($a0) + sw $v0, SMD_PRI_tpage($a0) + +$not_textured: + + jr $ra + move $v0, $a0 + +$end_prim: + + jr $ra + move $v0, $0 + \ No newline at end of file diff --git a/examples/fpscam/clip.c b/examples/fpscam/clip.c deleted file mode 100644 index 7f2b780..0000000 --- a/examples/fpscam/clip.c +++ /dev/null @@ -1,108 +0,0 @@ -/* Polygon clip detection code - * - * The polygon clipping logic is based on the Cohen-Sutherland algorithm, but - * only the off-screen detection logic is used to determine which polygon edges - * are off-screen. - * - * In tri_clip, the following edges are checked as follows: - * - * |\ - * | \ - * | \ - * | \ - * |-------- - * - * In quad_clip, the following edges are checked as follows: - * - * |---------| - * | \ / | - * | \ / | - * | / \ | - * | / \ | - * |---------| - * - * The inner portion of the quad is checked, otherwise the quad will be - * culled out if the camera faces right into it, where all four edges - * are off-screen at once. - * - */ - -#include "clip.h" - -#define CLIP_LEFT 1 -#define CLIP_RIGHT 2 -#define CLIP_TOP 4 -#define CLIP_BOTTOM 8 - -int test_clip(RECT *clip, short x, short y) { - - // Tests which corners of the screen a point lies outside of - - int result = 0; - - if ( x < clip->x ) { - result |= CLIP_LEFT; - } - - if ( x >= (clip->x+(clip->w-1)) ) { - result |= CLIP_RIGHT; - } - - if ( y < clip->y ) { - result |= CLIP_TOP; - } - - if ( y >= (clip->y+(clip->h-1)) ) { - result |= CLIP_BOTTOM; - } - - return result; - -} - -int tri_clip(RECT *clip, DVECTOR *v0, DVECTOR *v1, DVECTOR *v2) { - - // Returns non-zero if a triangle is outside the screen boundaries - - short c[3]; - - c[0] = test_clip(clip, v0->vx, v0->vy); - c[1] = test_clip(clip, v1->vx, v1->vy); - c[2] = test_clip(clip, v2->vx, v2->vy); - - if ( ( c[0] & c[1] ) == 0 ) - return 0; - if ( ( c[1] & c[2] ) == 0 ) - return 0; - if ( ( c[2] & c[0] ) == 0 ) - return 0; - - return 1; -} - -int quad_clip(RECT *clip, DVECTOR *v0, DVECTOR *v1, DVECTOR *v2, DVECTOR *v3) { - - // Returns non-zero if a quad is outside the screen boundaries - - short c[4]; - - c[0] = test_clip(clip, v0->vx, v0->vy); - c[1] = test_clip(clip, v1->vx, v1->vy); - c[2] = test_clip(clip, v2->vx, v2->vy); - c[3] = test_clip(clip, v3->vx, v3->vy); - - if ( ( c[0] & c[1] ) == 0 ) - return 0; - if ( ( c[1] & c[2] ) == 0 ) - return 0; - if ( ( c[2] & c[3] ) == 0 ) - return 0; - if ( ( c[3] & c[0] ) == 0 ) - return 0; - if ( ( c[0] & c[2] ) == 0 ) - return 0; - if ( ( c[1] & c[3] ) == 0 ) - return 0; - - return 1; -} \ No newline at end of file diff --git a/examples/fpscam/clip.h b/examples/fpscam/clip.h deleted file mode 100644 index 3b428bb..0000000 --- a/examples/fpscam/clip.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _CLIP_H -#define _CLIP_H - -#include -#include - -/* tri_clip - * - * Returns non-zero if a triangle (v0, v1, v2) is outside 'clip'. - * - * clip - Clipping area - * v0,v1,v2 - Triangle coordinates - * - */ -int tri_clip(RECT *clip, DVECTOR *v0, DVECTOR *v1, DVECTOR *v2); - -/* quad_clip - * - * Returns non-zero if a quad (v0, v1, v2, v3) is outside 'clip'. - * - * clip - Clipping area - * v0,v1,v2,v3 - Quad coordinates - * - */ -int quad_clip(RECT *clip, DVECTOR *v0, DVECTOR *v1, DVECTOR *v2, DVECTOR *v3); - -#endif // _CLIP_H \ No newline at end of file diff --git a/examples/fpscam/lookat.c b/examples/fpscam/lookat.c deleted file mode 100644 index d7c9ce4..0000000 --- a/examples/fpscam/lookat.c +++ /dev/null @@ -1,40 +0,0 @@ -// LookAt matrix code (may be implemented into libpsxgte soon) - -#include "lookat.h" - -void crossProduct(SVECTOR *v0, SVECTOR *v1, VECTOR *out) { - - out->vx = ((v0->vy*v1->vz)-(v0->vz*v1->vy))>>12; - out->vy = ((v0->vz*v1->vx)-(v0->vx*v1->vz))>>12; - out->vz = ((v0->vx*v1->vy)-(v0->vy*v1->vx))>>12; - -} - -void LookAt(VECTOR *eye, VECTOR *at, SVECTOR *up, MATRIX *mtx) { - - VECTOR taxis; - SVECTOR zaxis; - SVECTOR xaxis; - SVECTOR yaxis; - VECTOR pos; - VECTOR vec; - - setVector(&taxis, at->vx-eye->vx, at->vy-eye->vy, at->vz-eye->vz); - VectorNormalS(&taxis, &zaxis); - crossProduct(&zaxis, up, &taxis); - VectorNormalS(&taxis, &xaxis); - crossProduct(&zaxis, &xaxis, &taxis); - VectorNormalS(&taxis, &yaxis); - - mtx->m[0][0] = xaxis.vx; mtx->m[1][0] = yaxis.vx; mtx->m[2][0] = zaxis.vx; - mtx->m[0][1] = xaxis.vy; mtx->m[1][1] = yaxis.vy; mtx->m[2][1] = zaxis.vy; - mtx->m[0][2] = xaxis.vz; mtx->m[1][2] = yaxis.vz; mtx->m[2][2] = zaxis.vz; - - pos.vx = -eye->vx;; - pos.vy = -eye->vy;; - pos.vz = -eye->vz;; - - ApplyMatrixLV(mtx, &pos, &vec); - TransMatrix(mtx, &vec); - -} \ No newline at end of file diff --git a/examples/fpscam/lookat.h b/examples/fpscam/lookat.h deleted file mode 100644 index c57e50a..0000000 --- a/examples/fpscam/lookat.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _LOOKAT_H -#define _LOOKAT_H - -#include -#include - -/* LookAt - * - * Generates a matrix that looks from 'eye' to 'at'. - * - * eye - Position of viewpoint - * at - Position to 'look at' from viewpoint - * up - Vector that defines the 'up' direction - * mtx - Matrix output - * - */ -void LookAt(VECTOR *eye, VECTOR *at, SVECTOR *up, MATRIX *mtx); - -#endif // _LOOKAT_H \ No newline at end of file diff --git a/examples/fpscam/main.c b/examples/fpscam/main.c deleted file mode 100644 index 9dedf06..0000000 --- a/examples/fpscam/main.c +++ /dev/null @@ -1,678 +0,0 @@ -/* - * LibPSn00b Example Programs - * - * First-Person and Look-At Camera Example - * 2019 Meido-Tek Productions / PSn00bSDK Project - * - * Demonstrates both a first person perspective camera implementation with - * full six degrees of movement using fixed point integer math and a look-at - * tracking perspective. This example also shows how to use BIOS controller - * functions and how to parse analog controller input. - * - * Controls: - * Up - Look up - * Down - Look down - * Left - Look left - * Right - Look right - * Triangle - Move forward - * Cross - Move backward - * Square - Strafe left - * Circle - Strafe right - * R1 - Slide up - * R2 - Slide down - * L1 - Look at cube - * Select - Exit program (only works with CD loaders) - * - * - * Example by Lameguy64 - * - * Changelog: - * - * July 18, 2019 - Initial version. - * - * Sep 24, 2019 - Added camera position display and _boot() exit. - * - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "clip.h" -#include "lookat.h" - -// OT and Packet Buffer sizes -#define OT_LEN 1024 -#define PACKET_LEN 8192 - -// Screen resolution -#define SCREEN_XRES 320 -#define SCREEN_YRES 240 - -// Screen center position -#define CENTERX SCREEN_XRES>>1 -#define CENTERY SCREEN_YRES>>1 - - -// Double buffer structure -typedef struct { - DISPENV disp; // Display environment - DRAWENV draw; // Drawing environment - int ot[OT_LEN]; // Ordering table - char p[PACKET_LEN]; // Packet buffer -} DB; - -// Double buffer variables -DB db[2]; -int db_active = 0; -char *db_nextpri; -RECT screen_clip; - -// Pad data buffer -char pad_buff[2][34]; - - -// For easier handling of vertex indexes -typedef struct { - short v0,v1,v2,v3; -} INDEX; - -// Cube vertices -SVECTOR cube_verts[] = { - { -100, -100, -100, 0 }, - { 100, -100, -100, 0 }, - { -100, 100, -100, 0 }, - { 100, 100, -100, 0 }, - { 100, -100, 100, 0 }, - { -100, -100, 100, 0 }, - { 100, 100, 100, 0 }, - { -100, 100, 100, 0 } -}; - -// Cube face normals -SVECTOR cube_norms[] = { - { 0, 0, -ONE, 0 }, - { 0, 0, ONE, 0 }, - { 0, -ONE, 0, 0 }, - { 0, ONE, 0, 0 }, - { -ONE, 0, 0, 0 }, - { ONE, 0, 0, 0 } -}; - -// Cube vertex indices -INDEX cube_indices[] = { - { 0, 1, 2, 3 }, - { 4, 5, 6, 7 }, - { 5, 4, 0, 1 }, - { 6, 7, 3, 2 }, - { 0, 2, 5, 7 }, - { 3, 1, 6, 4 } -}; - -// Number of faces of cube -#define CUBE_FACES 6 - - -// Light color matrix -// Each column represents the color matrix of each light source and is -// used as material color when using gte_ncs() or multiplied by a -// source color when using gte_nccs(). 4096 is 1.0 in this matrix -// A column of zeroes effectively disables the light source. -MATRIX color_mtx = { - ONE, 0, 0, // Red - 0, 0, 0, // Green - ONE, 0, 0 // Blue -}; - -// Light matrix -// Each row represents a vector direction of each light source. -// An entire row of zeroes effectively disables the light source. -MATRIX light_mtx = { - /* X, Y, Z */ - -2048 , -2048 , -2048, - 0 , 0 , 0, - 0 , 0 , 0 -}; - - -// Function declarations -void init(); -void display(); -void sort_cube(MATRIX *mtx, VECTOR *pos, SVECTOR *rot); - - -// Main function -int main() { - - int i,p,xy_temp; - int px,py; - - SVECTOR rot; // Rotation vector for cube - VECTOR pos; // Position vector for cube - - SVECTOR verts[17][17]; // Vertex array for floor - - VECTOR cam_pos; // Camera position (in fixed point integers) - VECTOR cam_rot; // Camera view angle (in fixed point integers) - int cam_mode; // Camera mode (between first-person and look-at) - - VECTOR tpos; // Translation value for matrix calculations - SVECTOR trot; // Rotation value for matrix calculations - MATRIX mtx,lmtx; // Rotation matrices for geometry and lighting - - PADTYPE *pad; // Pad structure pointer for parsing controller - - POLY_F4 *pol4; // Flat shaded quad primitive pointer - - - // Init graphics and GTE - init(); - - - // Set coordinates to the vertex array for the floor - for( py=0; py<17; py++ ) { - for( px=0; px<17; px++ ) { - - setVector( &verts[py][px], - (100*(px-8))-50, - 0, - (100*(py-8))-50 ); - - } - } - - - // Camera default coordinates - setVector( &cam_pos, 0, ONE*-200, 0 ); - setVector( &cam_rot, 0, 0, 0 ); - - - // Main loop - while( 1 ) { - - // Set pad buffer data to pad pointer - pad = (PADTYPE*)&pad_buff[0][0]; - - // Parse controller input - cam_mode = 0; - - // Divide out fractions of camera rotation - trot.vx = cam_rot.vx >> 12; - trot.vy = cam_rot.vy >> 12; - trot.vz = cam_rot.vz >> 12; - - if( pad->stat == 0 ) { - - // For digital pad, dual-analog and dual-shock - if( ( pad->type == 0x4 ) || ( pad->type == 0x5 ) || ( pad->type == 0x7 ) ) { - - // The button status bits are inverted, - // so 0 means pressed in this case - - // Look controls - if( !(pad->btn&PAD_UP) ) { - - // Look up - cam_rot.vx -= ONE*8; - - } else if( !(pad->btn&PAD_DOWN) ) { - - // Look down - cam_rot.vx += ONE*8; - - } - - if( !(pad->btn&PAD_LEFT) ) { - - // Look left - cam_rot.vy += ONE*8; - - } else if( !(pad->btn&PAD_RIGHT) ) { - - // Look right - cam_rot.vy -= ONE*8; - - } - - // Movement controls - if( !(pad->btn&PAD_TRIANGLE) ) { - - // Move forward - cam_pos.vx -= (( isin( trot.vy )*icos( trot.vx ) )>>12)<<2; - cam_pos.vy += isin( trot.vx )<<2; - cam_pos.vz += (( icos( trot.vy )*icos( trot.vx ) )>>12)<<2; - - } else if( !(pad->btn&PAD_CROSS) ) { - - // Move backward - cam_pos.vx += (( isin( trot.vy )*icos( trot.vx ) )>>12)<<2; - cam_pos.vy -= isin( trot.vx )<<2; - cam_pos.vz -= (( icos( trot.vy )*icos( trot.vx ) )>>12)<<2; - - } - - if( !(pad->btn&PAD_SQUARE ) ) { - - // Slide left - cam_pos.vx -= icos( trot.vy )<<2; - cam_pos.vz -= isin( trot.vy )<<2; - - } else if( !(pad->btn&PAD_CIRCLE ) ) { - - // Slide right - cam_pos.vx += icos( trot.vy )<<2; - cam_pos.vz += isin( trot.vy )<<2; - - } - - if( !(pad->btn&PAD_R1) ) { - - // Slide up - cam_pos.vx -= (( isin( trot.vy )*isin( trot.vx ) )>>12)<<2; - cam_pos.vy -= icos( trot.vx )<<2; - cam_pos.vz += (( icos( trot.vy )*isin( trot.vx ) )>>12)<<2; - - } - - if( !(pad->btn&PAD_R2) ) { - - // Slide down - cam_pos.vx += (( isin( trot.vy )*isin( trot.vx ) )>>12)<<2; - cam_pos.vy += icos( trot.vx )<<2; - cam_pos.vz -= (( icos( trot.vy )*isin( trot.vx ) )>>12)<<2; - - } - - // Look at cube - if( !(pad->btn&PAD_L1) ) { - - cam_mode = 1; - - } - - if( !(pad->btn&PAD_SELECT) ) { - _boot(); - } - - } - - // For dual-analog and dual-shock (analog input) - if( ( pad->type == 0x5 ) || ( pad->type == 0x7 ) ) { - - // Moving forwards and backwards - if( ( (pad->ls_y-128) < -16 ) || ( (pad->ls_y-128) > 16 ) ) { - - cam_pos.vx += ((( isin( trot.vy )*icos( trot.vx ) )>>12)*(pad->ls_y-128))>>5; - cam_pos.vy -= (isin( trot.vx )*(pad->ls_y-128))>>5; - cam_pos.vz -= ((( icos( trot.vy )*icos( trot.vx ) )>>12)*(pad->ls_y-128))>>5; - - } - - // Strafing left and right - if( ( (pad->ls_x-128) < -16 ) || ( (pad->ls_x-128) > 16 ) ) { - cam_pos.vx += (icos( trot.vy )*(pad->ls_x-128))>>5; - cam_pos.vz += (isin( trot.vy )*(pad->ls_x-128))>>5; - } - - // Look up and down - if( ( (pad->rs_y-128) < -16 ) || ( (pad->rs_y-128) > 16 ) ) { - cam_rot.vx += (pad->rs_y-128)<<9; - } - - // Look left and right - if( ( (pad->rs_x-128) < -16 ) || ( (pad->rs_x-128) > 16 ) ) { - cam_rot.vy -= (pad->rs_x-128)<<9; - } - - } - - } - - // Print out some info - FntPrint(-1, "BUTTONS=%04x\n", pad->btn); - FntPrint(-1, "X=%d Y=%d Z=%d\n", - cam_pos.vx>>12, - cam_pos.vy>>12, - cam_pos.vz>>12); - FntPrint(-1, "RX=%d RY=%d\n", - cam_rot.vx>>12, - cam_rot.vy>>12); - - // First-person camera mode - if( cam_mode == 0 ) { - - // Set rotation to the matrix - RotMatrix( &trot, &mtx ); - - // Divide out the fractions of camera coordinates and invert - // the sign, so camera coordinates will line up to world - // (or geometry) coordinates - tpos.vx = -cam_pos.vx >> 12; - tpos.vy = -cam_pos.vy >> 12; - tpos.vz = -cam_pos.vz >> 12; - - // Apply rotation of matrix to translation value to achieve a - // first person perspective - ApplyMatrixLV( &mtx, &tpos, &tpos ); - - // Set translation matrix - TransMatrix( &mtx, &tpos ); - - // Tracking mode - } else { - - // Vector that defines the 'up' direction of the camera - SVECTOR up = { 0, -ONE, 0 }; - - // Divide out fractions of camera coordinates - tpos.vx = cam_pos.vx >> 12; - tpos.vy = cam_pos.vy >> 12; - tpos.vz = cam_pos.vz >> 12; - - // Look at the cube - LookAt(&tpos, &pos, &up, &mtx); - - } - - // Set rotation and translation matrix - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - // Draw the floor - pol4 = (POLY_F4*)db_nextpri; - - for( py=0; py<16; py++ ) { - for( px=0; px<16; px++ ) { - - // Load first three vertices to GTE - gte_ldv3( - &verts[py][px], - &verts[py][px+1], - &verts[py+1][px] ); - - gte_rtpt(); - - gte_avsz3(); - gte_stotz( &p ); - - if( ( (p>>2) >= OT_LEN ) || ( (p>>2) <= 0 ) ) - continue; - - setPolyF4( pol4 ); - - // Set the projected vertices to the primitive - gte_stsxy0( &pol4->x0 ); - gte_stsxy1( &pol4->x1 ); - gte_stsxy2( &pol4->x2 ); - - // Compute the last vertex and set the result - gte_ldv0( &verts[py+1][px+1] ); - gte_rtps(); - gte_stsxy( &pol4->x3 ); - - // Test if quad is off-screen, discard if so - // Clipping is important as it not only prevents primitive - // overflows (tends to happen on textured polys) but also - // saves packet buffer space and speeds up rendering. - if( quad_clip( &screen_clip, - (DVECTOR*)&pol4->x0, (DVECTOR*)&pol4->x1, - (DVECTOR*)&pol4->x2, (DVECTOR*)&pol4->x3 ) ) - continue; - - gte_avsz4(); - gte_stotz( &p ); - - if((px+py)&0x1) { - setRGB0( pol4, 128, 128, 128 ); - } else { - setRGB0( pol4, 255, 255, 255 ); - } - - addPrim( db[db_active].ot+(p>>2), pol4 ); - pol4++; - - } - } - - // Update nextpri variable (very important) - db_nextpri = (char*)pol4; - - - // Position the cube going around the floor bouncily - setVector( &pos, - isin( rot.vy )>>4, - -300+(isin( rot.vy<<2 )>>5), - icos( rot.vy )>>3 ); - - // Sort cube - sort_cube( &mtx, &pos, &rot ); - - // Make the cube SPEEN - rot.vx += 8; - rot.vy += 8; - - - // Flush text to drawing area - FntFlush(-1); - - // Swap buffers and draw the primitives - display(); - - } - - return 0; - -} - -void sort_cube(MATRIX *mtx, VECTOR *pos, SVECTOR *rot) { - - int i,p; - POLY_F4 *pol4; - - // Object and light matrix for object - MATRIX omtx,lmtx; - - // Set object rotation and position - RotMatrix( rot, &omtx ); - TransMatrix( &omtx, pos ); - - // Multiply light matrix to object matrix - MulMatrix0( &light_mtx, &omtx, &lmtx ); - - // Set result to GTE light matrix - gte_SetLightMatrix( &lmtx ); - - // Composite coordinate matrix transform, so object will be rotated and - // positioned relative to camera matrix (mtx), so it'll appear as - // world-space relative. - CompMatrixLV( mtx, &omtx, &omtx ); - - // Save matrix - PushMatrix(); - - // Set matrices - gte_SetRotMatrix( &omtx ); - gte_SetTransMatrix( &omtx ); - - // Sort the cube - pol4 = (POLY_F4*)db_nextpri; - - for( i=0; i>2) <= 0) || ((p>>2) >= OT_LEN) ) - continue; - - // Initialize a quad primitive - setPolyF4( pol4 ); - - // Set the projected vertices to the primitive - gte_stsxy0( &pol4->x0 ); - gte_stsxy1( &pol4->x1 ); - gte_stsxy2( &pol4->x2 ); - - // Compute the last vertex and set the result - gte_ldv0( &cube_verts[cube_indices[i].v3] ); - gte_rtps(); - gte_stsxy( &pol4->x3 ); - - // Test if quad is off-screen, discard if so - if( quad_clip( &screen_clip, - (DVECTOR*)&pol4->x0, (DVECTOR*)&pol4->x1, - (DVECTOR*)&pol4->x2, (DVECTOR*)&pol4->x3 ) ) - continue; - - // Load primitive color even though gte_ncs() doesn't use it. - // This is so the GTE will output a color result with the - // correct primitive code. - gte_ldrgb( &pol4->r0 ); - - // Load the face normal - gte_ldv0( &cube_norms[i] ); - - // Normal Color Single - gte_ncs(); - - // Store result to the primitive - gte_strgb( &pol4->r0 ); - - gte_avsz4(); - gte_stotz( &p ); - - // Sort primitive to the ordering table - addPrim( db[db_active].ot+(p>>2), pol4 ); - - // Advance to make another primitive - pol4++; - - } - - // Update nextpri - db_nextpri = (char*)pol4; - - // Restore matrix - PopMatrix(); - -} - -void init() { - - // Reset the GPU, also installs a VSync event handler - ResetGraph( 0 ); - - // Set display and draw environment areas - // (display and draw areas must be separate, otherwise hello flicker) - SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - - // Enable draw area clear and dither processing - setRGB0( &db[0].draw, 63, 0, 127 ); - db[0].draw.isbg = 1; - db[0].draw.dtd = 1; - - - // Define the second set of display/draw environments - SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); - - setRGB0( &db[1].draw, 63, 0, 127 ); - db[1].draw.isbg = 1; - db[1].draw.dtd = 1; - - // Apply the drawing environment of the first double buffer - PutDrawEnv( &db[0].draw ); - - // Clear both ordering tables to make sure they are clean at the start - ClearOTagR( db[0].ot, OT_LEN ); - ClearOTagR( db[1].ot, OT_LEN ); - - // Set primitive pointer address - db_nextpri = db[0].p; - - // Set clip region - setRECT( &screen_clip, 0, 0, SCREEN_XRES, SCREEN_YRES ); - - - // Initialize the GTE - InitGeom(); - - // Set GTE offset (recommended method of centering) - gte_SetGeomOffset( CENTERX, CENTERY ); - - // Set screen depth (basically FOV control, W/2 works best) - gte_SetGeomScreen( CENTERX ); - - // Set light ambient color and light color matrix - gte_SetBackColor( 63, 63, 63 ); - gte_SetColorMatrix( &color_mtx ); - - - // Init BIOS pad driver and set pad buffers (buffers are updated - // automatically on every V-Blank) - InitPAD(&pad_buff[0][0], 34, &pad_buff[1][0], 34); - - // Start pad - StartPAD(); - - // Don't make pad driver acknowledge V-Blank IRQ (recommended) - ChangeClearPAD(0); - - // Load font and open a text stream - FntLoad(960, 0); - FntOpen(0, 8, 320, 216, 0, 100); - -} - -void display() { - - // Wait for GPU to finish drawing and vertical retrace - DrawSync( 0 ); - VSync( 0 ); - - // Swap buffers - db_active ^= 1; - db_nextpri = db[db_active].p; - - // Clear the OT of the next frame - ClearOTagR( db[db_active].ot, OT_LEN ); - - // Apply display/drawing environments - PutDrawEnv( &db[db_active].draw ); - PutDispEnv( &db[db_active].disp ); - - // Enable display - SetDispMask( 1 ); - - // Start drawing the OT of the last buffer - DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); - -} - diff --git a/examples/fpscam/makefile b/examples/fpscam/makefile deleted file mode 100644 index 4f344eb..0000000 --- a/examples/fpscam/makefile +++ /dev/null @@ -1,39 +0,0 @@ -include ../sdk-common.mk - -TARGET = fpscam.elf - -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) - -INCLUDE += -LIBDIRS += - -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc - -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x - -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -AS = $(PREFIX)as -LD = $(PREFIX)ld - -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/graphics/balls/ball16c.h b/examples/graphics/balls/ball16c.h new file mode 100644 index 0000000..c79f273 --- /dev/null +++ b/examples/graphics/balls/ball16c.h @@ -0,0 +1,16 @@ +unsigned int ball16c_size=192; +unsigned char ball16c[] = { +0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, +0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, +0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, +0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, +0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, +0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, +0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, +0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, +0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, +0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, +0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, +0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, +0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 +}; diff --git a/examples/graphics/balls/ball16c.tim b/examples/graphics/balls/ball16c.tim new file mode 100644 index 0000000..e2a5d17 Binary files /dev/null and b/examples/graphics/balls/ball16c.tim differ diff --git a/examples/graphics/balls/main.c b/examples/graphics/balls/main.c new file mode 100644 index 0000000..89c8063 --- /dev/null +++ b/examples/graphics/balls/main.c @@ -0,0 +1,228 @@ +/* + * LibPSn00b Example Programs + * + * Balls Example + * 2019 Meido-Tek Productions / PSn00bSDK Project + * + * Draws a bunch of ball sprites that bounce around the screen, + * along with a ball snake that might be difficult to see. + * + * + * Example by Lameguy64 + * + * Changelog: + * + * November 20, 2018 - Initial version. + * + */ + +#include +#include +#include +#include +#include +#include "ball16c.h" + + +#define MAX_BALLS 1024 + +#define OT_LEN 8 + +#define SCREEN_XRES 640 +#define SCREEN_YRES 480 + +#define CENTER_X SCREEN_XRES/2 +#define CENTER_Y SCREEN_YRES/2 + + +/* Display and drawing environments */ +DISPENV disp; +DRAWENV draw; + +char pribuff[2][65536]; /* Primitive packet buffers */ +unsigned int ot[2][OT_LEN]; /* Ordering tables */ +char *nextpri; /* Pointer to next packet buffer offset */ +int db = 0; /* Double buffer index */ + + +/* Ball struct and array */ +typedef struct { + short x,y; + short xdir,ydir; + unsigned char r,g,b,p; +} BALL_TYPE; + +BALL_TYPE balls[MAX_BALLS]; + + +/* TIM image parameters for loading the ball texture and drawing sprites */ +TIM_IMAGE tim; + + +void init() { + + int i; + + /* Reset GPU (also installs event handler for VSync) */ + printf("Init GPU... "); + ResetGraph( 0 ); + printf("Done.\n"); + + + printf("Set video mode... "); + + /* Set display and draw environment parameters */ + SetDefDispEnv( &disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); + disp.isinter = 1; /* Enable interlace (required for hires) */ + + /* Set clear color, area clear and dither processing */ + setRGB0( &draw, 63, 0, 127 ); + draw.isbg = 1; + draw.dtd = 1; + + /* Apply the display and drawing environments */ + PutDispEnv( &disp ); + PutDrawEnv( &draw ); + + /* Enable video output */ + SetDispMask( 1 ); + + printf("Done.\n"); + + + /* Upload the ball texture */ + printf("Upload texture... "); + GetTimInfo( (unsigned int*)ball16c, &tim ); /* Get TIM parameters */ + + LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */ + if( tim.mode & 0x8 ) { + LoadImage( tim.crect, tim.caddr ); /* Upload CLUT if present */ + } + + printf("Done.\n"); + + + /* Calculate ball positions */ + printf("Calculating balls... "); + + for(i=0; i>5), + (CENTER_Y-8)-(icos((counter-(i<<2))<<3)>>5) ); + setRGB0( sprt, rand()%256, rand()%256, rand()%256 ); + setUV0( sprt, 0, 0 ); + setClut( sprt, tim.crect->x, tim.crect->y ); + + addPrim( ot[db]+(OT_LEN-1), sprt ); + sprt++; + + } + + /* Sort the balls */ + for( i=0; ix, tim.crect->y ); + + addPrim( ot[db]+(OT_LEN-1), sprt ); + sprt++; + + balls[i].x += balls[i].xdir; + balls[i].y += balls[i].ydir; + + if( ( balls[i].x+16 ) > 640 ) { + balls[i].xdir = -2; + } else if( balls[i].x < 0 ) { + balls[i].xdir = 2; + } + + if( ( balls[i].y+16 ) > 480 ) { + balls[i].ydir = -2; + } else if( balls[i].y < 0 ) { + balls[i].ydir = 2; + } + + } + nextpri = (char*)sprt; + + + /* Sort a TPage primitive so the sprites will draw pixels from */ + /* the correct texture page in VRAM */ + tpri = (DR_TPAGE*)nextpri; + setDrawTPage( tpri, 0, 0, + getTPage(0, 0, tim.prect->x, tim.prect->y )); + addPrim( ot[db]+(OT_LEN-1), tpri ); + nextpri += sizeof(DR_TPAGE); + + /* Wait for GPU and VSync */ + DrawSync( 0 ); + VSync( 0 ); + + /* Since draw.isbg is non-zero this clears the screen */ + PutDrawEnv( &draw ); + + /* Begin drawing the new frame */ + DrawOTag( ot[db]+(OT_LEN-1) ); + + /* Alternate to the next buffer */ + db = !db; + + /* Increment counter for the snake animation */ + counter++; + + } + + return 0; + +} diff --git a/examples/graphics/balls/makefile b/examples/graphics/balls/makefile new file mode 100644 index 0000000..50ed0f1 --- /dev/null +++ b/examples/graphics/balls/makefile @@ -0,0 +1,60 @@ +include ../../sdk-common.mk + +# Project target name +TARGET = balls.elf + +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CPPFILES = $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +# Determine object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) + +# Project specific include and library directories +# (use -I for include dirs, -L for library dirs) +INCLUDE += +LIBDIRS += + +# Libraries to link +LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc + +# C compiler flags +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections + +# C++ compiler flags +CPPFLAGS = $(CFLAGS) -fno-exceptions + +# Assembler flags +AFLAGS = -g -msoft-float + +# Linker flags +LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ + -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x + +# Toolchain programs +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/graphics/billboard/billboard.c b/examples/graphics/billboard/billboard.c new file mode 100644 index 0000000..bba5dda --- /dev/null +++ b/examples/graphics/billboard/billboard.c @@ -0,0 +1,260 @@ +/* + * LibPSn00b Example Programs + * + * GTE Billboarding Sprites Example + * 2019 Meido-Tek Productions / PSn00bSDK Project + * + * Displays a bunch of sprites placed on the screen using 3D coordinates + * that scale according to the distance from the screen. This is a quick + * modification of the GTE cube example. + * + * Billboard sprites are useful for 2D projectiles flying across 3D space, + * particle effects such as smoke as well as characters and objects + * represented as 2D sprites. + * + * Example by Lameguy64 + * + * Changelog: + * + * Sep 24, 2019 - Initial version. + * + */ + +#include +#include +#include +#include + +/* OT and Packet Buffer sizes */ +#define OT_LEN 256 +#define PACKET_LEN 1024 + +/* Screen resolution */ +#define SCREEN_XRES 320 +#define SCREEN_YRES 240 + +/* Screen center position */ +#define CENTERX SCREEN_XRES>>1 +#define CENTERY SCREEN_YRES>>1 + + +/* Double buffer structure */ +typedef struct { + DISPENV disp; /* Display environment */ + DRAWENV draw; /* Drawing environment */ + int ot[OT_LEN]; /* Ordering table */ + char p[PACKET_LEN]; /* Packet buffer */ +} DB; + +/* Double buffer variables */ +DB db[2]; +int db_active = 0; +char *db_nextpri; + +extern int tim_image[]; +TIM_IMAGE tim; + +/* For easier handling of vertex indices */ +typedef struct { + short v0,v1,v2,v3; +} INDEX; + +/* Sprite position vertices */ +SVECTOR verts[] = { + { -50, -50, -50, 0 }, + { 50, -50, -50, 0 }, + { -50, 50, -50, 0 }, + { 50, 50, -50, 0 }, + { 50, -50, 50, 0 }, + { -50, -50, 50, 0 }, + { 50, 50, 50, 0 }, + { -50, 50, 50, 0 } +}; + + +/* Function declarations */ +void init(); +void display(); + + +/* Main function */ +int main() { + + int i,p,sz; + + SVECTOR rot = { 0 }; /* Rotation vector for Rotmatrix */ + VECTOR pos = { 0, 0, 160 }; /* Translation vector for TransMatrix */ + MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ + + POLY_FT4 *quad; /* Flat shaded quad primitive pointer */ + SVECTOR spos; + + /* Init graphics and GTE */ + init(); + + + /* Main loop */ + while( 1 ) { + + /* Set rotation and translation to the matrix */ + RotMatrix( &rot, &mtx ); + TransMatrix( &mtx, &pos ); + + /* Set rotation and translation matrix */ + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + /* Make the sprites revolve around */ + rot.vy += 16; + rot.vz += 16; + + /* Draw the sprites */ + quad = (POLY_FT4*)db_nextpri; + + for( i=0; i<8; i++ ) { + + // Load the 3D coordinate of the sprite to GTE + gte_ldv0(&verts[i]); + + // Rotation, Translation and Perspective Single + gte_rtps(); + + // Store depth + gte_stsz(&p); + + // Don't sort sprite if depth is zero + // (or divide by zero will happen later) + if( p > 0 ) { + + // Store result to position vector + gte_stsxy2(&spos); + + // Calculate sprite size, the divide operation might be a + // performance killer but it's likely faster than performing + // a lookat operation between sprite and camera, which some + // billboard sprite implementations use. + sz = (16*CENTERX)/p; + + // Prepare quad primitive + setPolyFT4(quad); + + // Set quad coordinates + setXY4(quad, + spos.vx-sz, spos.vy-sz, + spos.vx+sz, spos.vy-sz, + spos.vx-sz, spos.vy+sz, + spos.vx+sz, spos.vy+sz); + + // Set color + setRGB0(quad, 128, 128, 128); + + // Set tpage + quad->tpage = getTPage(tim.mode&0x8, 0, tim.prect->x, tim.prect->y); + + // Set CLUT + setClut(quad, tim.crect->x, tim.crect->y); + + // Set texture coordinates + setUVWH(quad, 0, 0, 64, 64); + + /* Sort primitive to the ordering table */ + addPrim(db[db_active].ot+(p>>2), quad); + + /* Advance to make another primitive */ + quad++; + + } + } + + /* Update nextpri variable */ + /* (IMPORTANT if you plan to sort more primitives after this) */ + db_nextpri = (char*)quad; + + /* Swap buffers and draw the primitives */ + display(); + + } + + return 0; + +} + +void init() { + + /* Reset the GPU, also installs a VSync event handler */ + ResetGraph( 0 ); + + /* Set display and draw environment areas */ + /* (display and draw areas must be separate, otherwise hello flicker) */ + SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + + /* Enable draw area clear and dither processing */ + setRGB0( &db[0].draw, 63, 0, 127 ); + db[0].draw.isbg = 1; + db[0].draw.dtd = 1; + + + /* Define the second set of display/draw environments */ + SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); + + setRGB0( &db[1].draw, 63, 0, 127 ); + db[1].draw.isbg = 1; + db[1].draw.dtd = 1; + + + /* Apply the drawing environment of the first double buffer */ + PutDrawEnv( &db[0].draw ); + + + /* Clear both ordering tables to make sure they are clean at the start */ + ClearOTagR( db[0].ot, OT_LEN ); + ClearOTagR( db[1].ot, OT_LEN ); + + /* Set primitive pointer address */ + db_nextpri = db[0].p; + + /* Initialize the GTE */ + InitGeom(); + + /* Set GTE offset (recommended method of centering) */ + gte_SetGeomOffset( CENTERX, CENTERY ); + + /* Set screen depth (basically FOV control, W/2 works best) */ + gte_SetGeomScreen( CENTERX ); + + GetTimInfo(tim_image, &tim); + + LoadImage(tim.prect, tim.paddr); + DrawSync(0); + + LoadImage(tim.crect, tim.caddr); + DrawSync(0); + +} + +void display() { + + /* Wait for GPU to finish drawing and vertical retrace */ + DrawSync( 0 ); + VSync( 0 ); + + /* Swap buffers */ + db_active ^= 1; + db_nextpri = db[db_active].p; + + /* Clear the OT of the next frame */ + ClearOTagR( db[db_active].ot, OT_LEN ); + + /* Apply display/drawing environments */ + PutDrawEnv( &db[db_active].draw ); + PutDispEnv( &db[db_active].disp ); + + /* Enable display */ + SetDispMask( 1 ); + + /* Start drawing the OT of the last buffer */ + DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); + +} \ No newline at end of file diff --git a/examples/graphics/billboard/makefile b/examples/graphics/billboard/makefile new file mode 100644 index 0000000..d6add7a --- /dev/null +++ b/examples/graphics/billboard/makefile @@ -0,0 +1,39 @@ +include ../../sdk-common.mk + +TARGET = billboard.elf + +CFILES = $(notdir $(wildcard *.c)) +CPPFILES = $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) + +INCLUDE += +LIBDIRS += + +LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc + +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +CPPFLAGS = $(CFLAGS) -fno-exceptions +AFLAGS = -g -msoft-float +LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x + +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/graphics/billboard/texture64.tim b/examples/graphics/billboard/texture64.tim new file mode 100644 index 0000000..d3aff3a Binary files /dev/null and b/examples/graphics/billboard/texture64.tim differ diff --git a/examples/graphics/billboard/tim.s b/examples/graphics/billboard/tim.s new file mode 100644 index 0000000..1fa8d69 --- /dev/null +++ b/examples/graphics/billboard/tim.s @@ -0,0 +1,7 @@ +.section .data + +.global tim_image +.type tim_image, @object +tim_image: + .incbin "texture64.tim" + \ No newline at end of file diff --git a/examples/graphics/fpscam/clip.c b/examples/graphics/fpscam/clip.c new file mode 100644 index 0000000..7f2b780 --- /dev/null +++ b/examples/graphics/fpscam/clip.c @@ -0,0 +1,108 @@ +/* Polygon clip detection code + * + * The polygon clipping logic is based on the Cohen-Sutherland algorithm, but + * only the off-screen detection logic is used to determine which polygon edges + * are off-screen. + * + * In tri_clip, the following edges are checked as follows: + * + * |\ + * | \ + * | \ + * | \ + * |-------- + * + * In quad_clip, the following edges are checked as follows: + * + * |---------| + * | \ / | + * | \ / | + * | / \ | + * | / \ | + * |---------| + * + * The inner portion of the quad is checked, otherwise the quad will be + * culled out if the camera faces right into it, where all four edges + * are off-screen at once. + * + */ + +#include "clip.h" + +#define CLIP_LEFT 1 +#define CLIP_RIGHT 2 +#define CLIP_TOP 4 +#define CLIP_BOTTOM 8 + +int test_clip(RECT *clip, short x, short y) { + + // Tests which corners of the screen a point lies outside of + + int result = 0; + + if ( x < clip->x ) { + result |= CLIP_LEFT; + } + + if ( x >= (clip->x+(clip->w-1)) ) { + result |= CLIP_RIGHT; + } + + if ( y < clip->y ) { + result |= CLIP_TOP; + } + + if ( y >= (clip->y+(clip->h-1)) ) { + result |= CLIP_BOTTOM; + } + + return result; + +} + +int tri_clip(RECT *clip, DVECTOR *v0, DVECTOR *v1, DVECTOR *v2) { + + // Returns non-zero if a triangle is outside the screen boundaries + + short c[3]; + + c[0] = test_clip(clip, v0->vx, v0->vy); + c[1] = test_clip(clip, v1->vx, v1->vy); + c[2] = test_clip(clip, v2->vx, v2->vy); + + if ( ( c[0] & c[1] ) == 0 ) + return 0; + if ( ( c[1] & c[2] ) == 0 ) + return 0; + if ( ( c[2] & c[0] ) == 0 ) + return 0; + + return 1; +} + +int quad_clip(RECT *clip, DVECTOR *v0, DVECTOR *v1, DVECTOR *v2, DVECTOR *v3) { + + // Returns non-zero if a quad is outside the screen boundaries + + short c[4]; + + c[0] = test_clip(clip, v0->vx, v0->vy); + c[1] = test_clip(clip, v1->vx, v1->vy); + c[2] = test_clip(clip, v2->vx, v2->vy); + c[3] = test_clip(clip, v3->vx, v3->vy); + + if ( ( c[0] & c[1] ) == 0 ) + return 0; + if ( ( c[1] & c[2] ) == 0 ) + return 0; + if ( ( c[2] & c[3] ) == 0 ) + return 0; + if ( ( c[3] & c[0] ) == 0 ) + return 0; + if ( ( c[0] & c[2] ) == 0 ) + return 0; + if ( ( c[1] & c[3] ) == 0 ) + return 0; + + return 1; +} \ No newline at end of file diff --git a/examples/graphics/fpscam/clip.h b/examples/graphics/fpscam/clip.h new file mode 100644 index 0000000..3b428bb --- /dev/null +++ b/examples/graphics/fpscam/clip.h @@ -0,0 +1,27 @@ +#ifndef _CLIP_H +#define _CLIP_H + +#include +#include + +/* tri_clip + * + * Returns non-zero if a triangle (v0, v1, v2) is outside 'clip'. + * + * clip - Clipping area + * v0,v1,v2 - Triangle coordinates + * + */ +int tri_clip(RECT *clip, DVECTOR *v0, DVECTOR *v1, DVECTOR *v2); + +/* quad_clip + * + * Returns non-zero if a quad (v0, v1, v2, v3) is outside 'clip'. + * + * clip - Clipping area + * v0,v1,v2,v3 - Quad coordinates + * + */ +int quad_clip(RECT *clip, DVECTOR *v0, DVECTOR *v1, DVECTOR *v2, DVECTOR *v3); + +#endif // _CLIP_H \ No newline at end of file diff --git a/examples/graphics/fpscam/lookat.c b/examples/graphics/fpscam/lookat.c new file mode 100644 index 0000000..d7c9ce4 --- /dev/null +++ b/examples/graphics/fpscam/lookat.c @@ -0,0 +1,40 @@ +// LookAt matrix code (may be implemented into libpsxgte soon) + +#include "lookat.h" + +void crossProduct(SVECTOR *v0, SVECTOR *v1, VECTOR *out) { + + out->vx = ((v0->vy*v1->vz)-(v0->vz*v1->vy))>>12; + out->vy = ((v0->vz*v1->vx)-(v0->vx*v1->vz))>>12; + out->vz = ((v0->vx*v1->vy)-(v0->vy*v1->vx))>>12; + +} + +void LookAt(VECTOR *eye, VECTOR *at, SVECTOR *up, MATRIX *mtx) { + + VECTOR taxis; + SVECTOR zaxis; + SVECTOR xaxis; + SVECTOR yaxis; + VECTOR pos; + VECTOR vec; + + setVector(&taxis, at->vx-eye->vx, at->vy-eye->vy, at->vz-eye->vz); + VectorNormalS(&taxis, &zaxis); + crossProduct(&zaxis, up, &taxis); + VectorNormalS(&taxis, &xaxis); + crossProduct(&zaxis, &xaxis, &taxis); + VectorNormalS(&taxis, &yaxis); + + mtx->m[0][0] = xaxis.vx; mtx->m[1][0] = yaxis.vx; mtx->m[2][0] = zaxis.vx; + mtx->m[0][1] = xaxis.vy; mtx->m[1][1] = yaxis.vy; mtx->m[2][1] = zaxis.vy; + mtx->m[0][2] = xaxis.vz; mtx->m[1][2] = yaxis.vz; mtx->m[2][2] = zaxis.vz; + + pos.vx = -eye->vx;; + pos.vy = -eye->vy;; + pos.vz = -eye->vz;; + + ApplyMatrixLV(mtx, &pos, &vec); + TransMatrix(mtx, &vec); + +} \ No newline at end of file diff --git a/examples/graphics/fpscam/lookat.h b/examples/graphics/fpscam/lookat.h new file mode 100644 index 0000000..c57e50a --- /dev/null +++ b/examples/graphics/fpscam/lookat.h @@ -0,0 +1,19 @@ +#ifndef _LOOKAT_H +#define _LOOKAT_H + +#include +#include + +/* LookAt + * + * Generates a matrix that looks from 'eye' to 'at'. + * + * eye - Position of viewpoint + * at - Position to 'look at' from viewpoint + * up - Vector that defines the 'up' direction + * mtx - Matrix output + * + */ +void LookAt(VECTOR *eye, VECTOR *at, SVECTOR *up, MATRIX *mtx); + +#endif // _LOOKAT_H \ No newline at end of file diff --git a/examples/graphics/fpscam/main.c b/examples/graphics/fpscam/main.c new file mode 100644 index 0000000..9dedf06 --- /dev/null +++ b/examples/graphics/fpscam/main.c @@ -0,0 +1,678 @@ +/* + * LibPSn00b Example Programs + * + * First-Person and Look-At Camera Example + * 2019 Meido-Tek Productions / PSn00bSDK Project + * + * Demonstrates both a first person perspective camera implementation with + * full six degrees of movement using fixed point integer math and a look-at + * tracking perspective. This example also shows how to use BIOS controller + * functions and how to parse analog controller input. + * + * Controls: + * Up - Look up + * Down - Look down + * Left - Look left + * Right - Look right + * Triangle - Move forward + * Cross - Move backward + * Square - Strafe left + * Circle - Strafe right + * R1 - Slide up + * R2 - Slide down + * L1 - Look at cube + * Select - Exit program (only works with CD loaders) + * + * + * Example by Lameguy64 + * + * Changelog: + * + * July 18, 2019 - Initial version. + * + * Sep 24, 2019 - Added camera position display and _boot() exit. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "clip.h" +#include "lookat.h" + +// OT and Packet Buffer sizes +#define OT_LEN 1024 +#define PACKET_LEN 8192 + +// Screen resolution +#define SCREEN_XRES 320 +#define SCREEN_YRES 240 + +// Screen center position +#define CENTERX SCREEN_XRES>>1 +#define CENTERY SCREEN_YRES>>1 + + +// Double buffer structure +typedef struct { + DISPENV disp; // Display environment + DRAWENV draw; // Drawing environment + int ot[OT_LEN]; // Ordering table + char p[PACKET_LEN]; // Packet buffer +} DB; + +// Double buffer variables +DB db[2]; +int db_active = 0; +char *db_nextpri; +RECT screen_clip; + +// Pad data buffer +char pad_buff[2][34]; + + +// For easier handling of vertex indexes +typedef struct { + short v0,v1,v2,v3; +} INDEX; + +// Cube vertices +SVECTOR cube_verts[] = { + { -100, -100, -100, 0 }, + { 100, -100, -100, 0 }, + { -100, 100, -100, 0 }, + { 100, 100, -100, 0 }, + { 100, -100, 100, 0 }, + { -100, -100, 100, 0 }, + { 100, 100, 100, 0 }, + { -100, 100, 100, 0 } +}; + +// Cube face normals +SVECTOR cube_norms[] = { + { 0, 0, -ONE, 0 }, + { 0, 0, ONE, 0 }, + { 0, -ONE, 0, 0 }, + { 0, ONE, 0, 0 }, + { -ONE, 0, 0, 0 }, + { ONE, 0, 0, 0 } +}; + +// Cube vertex indices +INDEX cube_indices[] = { + { 0, 1, 2, 3 }, + { 4, 5, 6, 7 }, + { 5, 4, 0, 1 }, + { 6, 7, 3, 2 }, + { 0, 2, 5, 7 }, + { 3, 1, 6, 4 } +}; + +// Number of faces of cube +#define CUBE_FACES 6 + + +// Light color matrix +// Each column represents the color matrix of each light source and is +// used as material color when using gte_ncs() or multiplied by a +// source color when using gte_nccs(). 4096 is 1.0 in this matrix +// A column of zeroes effectively disables the light source. +MATRIX color_mtx = { + ONE, 0, 0, // Red + 0, 0, 0, // Green + ONE, 0, 0 // Blue +}; + +// Light matrix +// Each row represents a vector direction of each light source. +// An entire row of zeroes effectively disables the light source. +MATRIX light_mtx = { + /* X, Y, Z */ + -2048 , -2048 , -2048, + 0 , 0 , 0, + 0 , 0 , 0 +}; + + +// Function declarations +void init(); +void display(); +void sort_cube(MATRIX *mtx, VECTOR *pos, SVECTOR *rot); + + +// Main function +int main() { + + int i,p,xy_temp; + int px,py; + + SVECTOR rot; // Rotation vector for cube + VECTOR pos; // Position vector for cube + + SVECTOR verts[17][17]; // Vertex array for floor + + VECTOR cam_pos; // Camera position (in fixed point integers) + VECTOR cam_rot; // Camera view angle (in fixed point integers) + int cam_mode; // Camera mode (between first-person and look-at) + + VECTOR tpos; // Translation value for matrix calculations + SVECTOR trot; // Rotation value for matrix calculations + MATRIX mtx,lmtx; // Rotation matrices for geometry and lighting + + PADTYPE *pad; // Pad structure pointer for parsing controller + + POLY_F4 *pol4; // Flat shaded quad primitive pointer + + + // Init graphics and GTE + init(); + + + // Set coordinates to the vertex array for the floor + for( py=0; py<17; py++ ) { + for( px=0; px<17; px++ ) { + + setVector( &verts[py][px], + (100*(px-8))-50, + 0, + (100*(py-8))-50 ); + + } + } + + + // Camera default coordinates + setVector( &cam_pos, 0, ONE*-200, 0 ); + setVector( &cam_rot, 0, 0, 0 ); + + + // Main loop + while( 1 ) { + + // Set pad buffer data to pad pointer + pad = (PADTYPE*)&pad_buff[0][0]; + + // Parse controller input + cam_mode = 0; + + // Divide out fractions of camera rotation + trot.vx = cam_rot.vx >> 12; + trot.vy = cam_rot.vy >> 12; + trot.vz = cam_rot.vz >> 12; + + if( pad->stat == 0 ) { + + // For digital pad, dual-analog and dual-shock + if( ( pad->type == 0x4 ) || ( pad->type == 0x5 ) || ( pad->type == 0x7 ) ) { + + // The button status bits are inverted, + // so 0 means pressed in this case + + // Look controls + if( !(pad->btn&PAD_UP) ) { + + // Look up + cam_rot.vx -= ONE*8; + + } else if( !(pad->btn&PAD_DOWN) ) { + + // Look down + cam_rot.vx += ONE*8; + + } + + if( !(pad->btn&PAD_LEFT) ) { + + // Look left + cam_rot.vy += ONE*8; + + } else if( !(pad->btn&PAD_RIGHT) ) { + + // Look right + cam_rot.vy -= ONE*8; + + } + + // Movement controls + if( !(pad->btn&PAD_TRIANGLE) ) { + + // Move forward + cam_pos.vx -= (( isin( trot.vy )*icos( trot.vx ) )>>12)<<2; + cam_pos.vy += isin( trot.vx )<<2; + cam_pos.vz += (( icos( trot.vy )*icos( trot.vx ) )>>12)<<2; + + } else if( !(pad->btn&PAD_CROSS) ) { + + // Move backward + cam_pos.vx += (( isin( trot.vy )*icos( trot.vx ) )>>12)<<2; + cam_pos.vy -= isin( trot.vx )<<2; + cam_pos.vz -= (( icos( trot.vy )*icos( trot.vx ) )>>12)<<2; + + } + + if( !(pad->btn&PAD_SQUARE ) ) { + + // Slide left + cam_pos.vx -= icos( trot.vy )<<2; + cam_pos.vz -= isin( trot.vy )<<2; + + } else if( !(pad->btn&PAD_CIRCLE ) ) { + + // Slide right + cam_pos.vx += icos( trot.vy )<<2; + cam_pos.vz += isin( trot.vy )<<2; + + } + + if( !(pad->btn&PAD_R1) ) { + + // Slide up + cam_pos.vx -= (( isin( trot.vy )*isin( trot.vx ) )>>12)<<2; + cam_pos.vy -= icos( trot.vx )<<2; + cam_pos.vz += (( icos( trot.vy )*isin( trot.vx ) )>>12)<<2; + + } + + if( !(pad->btn&PAD_R2) ) { + + // Slide down + cam_pos.vx += (( isin( trot.vy )*isin( trot.vx ) )>>12)<<2; + cam_pos.vy += icos( trot.vx )<<2; + cam_pos.vz -= (( icos( trot.vy )*isin( trot.vx ) )>>12)<<2; + + } + + // Look at cube + if( !(pad->btn&PAD_L1) ) { + + cam_mode = 1; + + } + + if( !(pad->btn&PAD_SELECT) ) { + _boot(); + } + + } + + // For dual-analog and dual-shock (analog input) + if( ( pad->type == 0x5 ) || ( pad->type == 0x7 ) ) { + + // Moving forwards and backwards + if( ( (pad->ls_y-128) < -16 ) || ( (pad->ls_y-128) > 16 ) ) { + + cam_pos.vx += ((( isin( trot.vy )*icos( trot.vx ) )>>12)*(pad->ls_y-128))>>5; + cam_pos.vy -= (isin( trot.vx )*(pad->ls_y-128))>>5; + cam_pos.vz -= ((( icos( trot.vy )*icos( trot.vx ) )>>12)*(pad->ls_y-128))>>5; + + } + + // Strafing left and right + if( ( (pad->ls_x-128) < -16 ) || ( (pad->ls_x-128) > 16 ) ) { + cam_pos.vx += (icos( trot.vy )*(pad->ls_x-128))>>5; + cam_pos.vz += (isin( trot.vy )*(pad->ls_x-128))>>5; + } + + // Look up and down + if( ( (pad->rs_y-128) < -16 ) || ( (pad->rs_y-128) > 16 ) ) { + cam_rot.vx += (pad->rs_y-128)<<9; + } + + // Look left and right + if( ( (pad->rs_x-128) < -16 ) || ( (pad->rs_x-128) > 16 ) ) { + cam_rot.vy -= (pad->rs_x-128)<<9; + } + + } + + } + + // Print out some info + FntPrint(-1, "BUTTONS=%04x\n", pad->btn); + FntPrint(-1, "X=%d Y=%d Z=%d\n", + cam_pos.vx>>12, + cam_pos.vy>>12, + cam_pos.vz>>12); + FntPrint(-1, "RX=%d RY=%d\n", + cam_rot.vx>>12, + cam_rot.vy>>12); + + // First-person camera mode + if( cam_mode == 0 ) { + + // Set rotation to the matrix + RotMatrix( &trot, &mtx ); + + // Divide out the fractions of camera coordinates and invert + // the sign, so camera coordinates will line up to world + // (or geometry) coordinates + tpos.vx = -cam_pos.vx >> 12; + tpos.vy = -cam_pos.vy >> 12; + tpos.vz = -cam_pos.vz >> 12; + + // Apply rotation of matrix to translation value to achieve a + // first person perspective + ApplyMatrixLV( &mtx, &tpos, &tpos ); + + // Set translation matrix + TransMatrix( &mtx, &tpos ); + + // Tracking mode + } else { + + // Vector that defines the 'up' direction of the camera + SVECTOR up = { 0, -ONE, 0 }; + + // Divide out fractions of camera coordinates + tpos.vx = cam_pos.vx >> 12; + tpos.vy = cam_pos.vy >> 12; + tpos.vz = cam_pos.vz >> 12; + + // Look at the cube + LookAt(&tpos, &pos, &up, &mtx); + + } + + // Set rotation and translation matrix + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + // Draw the floor + pol4 = (POLY_F4*)db_nextpri; + + for( py=0; py<16; py++ ) { + for( px=0; px<16; px++ ) { + + // Load first three vertices to GTE + gte_ldv3( + &verts[py][px], + &verts[py][px+1], + &verts[py+1][px] ); + + gte_rtpt(); + + gte_avsz3(); + gte_stotz( &p ); + + if( ( (p>>2) >= OT_LEN ) || ( (p>>2) <= 0 ) ) + continue; + + setPolyF4( pol4 ); + + // Set the projected vertices to the primitive + gte_stsxy0( &pol4->x0 ); + gte_stsxy1( &pol4->x1 ); + gte_stsxy2( &pol4->x2 ); + + // Compute the last vertex and set the result + gte_ldv0( &verts[py+1][px+1] ); + gte_rtps(); + gte_stsxy( &pol4->x3 ); + + // Test if quad is off-screen, discard if so + // Clipping is important as it not only prevents primitive + // overflows (tends to happen on textured polys) but also + // saves packet buffer space and speeds up rendering. + if( quad_clip( &screen_clip, + (DVECTOR*)&pol4->x0, (DVECTOR*)&pol4->x1, + (DVECTOR*)&pol4->x2, (DVECTOR*)&pol4->x3 ) ) + continue; + + gte_avsz4(); + gte_stotz( &p ); + + if((px+py)&0x1) { + setRGB0( pol4, 128, 128, 128 ); + } else { + setRGB0( pol4, 255, 255, 255 ); + } + + addPrim( db[db_active].ot+(p>>2), pol4 ); + pol4++; + + } + } + + // Update nextpri variable (very important) + db_nextpri = (char*)pol4; + + + // Position the cube going around the floor bouncily + setVector( &pos, + isin( rot.vy )>>4, + -300+(isin( rot.vy<<2 )>>5), + icos( rot.vy )>>3 ); + + // Sort cube + sort_cube( &mtx, &pos, &rot ); + + // Make the cube SPEEN + rot.vx += 8; + rot.vy += 8; + + + // Flush text to drawing area + FntFlush(-1); + + // Swap buffers and draw the primitives + display(); + + } + + return 0; + +} + +void sort_cube(MATRIX *mtx, VECTOR *pos, SVECTOR *rot) { + + int i,p; + POLY_F4 *pol4; + + // Object and light matrix for object + MATRIX omtx,lmtx; + + // Set object rotation and position + RotMatrix( rot, &omtx ); + TransMatrix( &omtx, pos ); + + // Multiply light matrix to object matrix + MulMatrix0( &light_mtx, &omtx, &lmtx ); + + // Set result to GTE light matrix + gte_SetLightMatrix( &lmtx ); + + // Composite coordinate matrix transform, so object will be rotated and + // positioned relative to camera matrix (mtx), so it'll appear as + // world-space relative. + CompMatrixLV( mtx, &omtx, &omtx ); + + // Save matrix + PushMatrix(); + + // Set matrices + gte_SetRotMatrix( &omtx ); + gte_SetTransMatrix( &omtx ); + + // Sort the cube + pol4 = (POLY_F4*)db_nextpri; + + for( i=0; i>2) <= 0) || ((p>>2) >= OT_LEN) ) + continue; + + // Initialize a quad primitive + setPolyF4( pol4 ); + + // Set the projected vertices to the primitive + gte_stsxy0( &pol4->x0 ); + gte_stsxy1( &pol4->x1 ); + gte_stsxy2( &pol4->x2 ); + + // Compute the last vertex and set the result + gte_ldv0( &cube_verts[cube_indices[i].v3] ); + gte_rtps(); + gte_stsxy( &pol4->x3 ); + + // Test if quad is off-screen, discard if so + if( quad_clip( &screen_clip, + (DVECTOR*)&pol4->x0, (DVECTOR*)&pol4->x1, + (DVECTOR*)&pol4->x2, (DVECTOR*)&pol4->x3 ) ) + continue; + + // Load primitive color even though gte_ncs() doesn't use it. + // This is so the GTE will output a color result with the + // correct primitive code. + gte_ldrgb( &pol4->r0 ); + + // Load the face normal + gte_ldv0( &cube_norms[i] ); + + // Normal Color Single + gte_ncs(); + + // Store result to the primitive + gte_strgb( &pol4->r0 ); + + gte_avsz4(); + gte_stotz( &p ); + + // Sort primitive to the ordering table + addPrim( db[db_active].ot+(p>>2), pol4 ); + + // Advance to make another primitive + pol4++; + + } + + // Update nextpri + db_nextpri = (char*)pol4; + + // Restore matrix + PopMatrix(); + +} + +void init() { + + // Reset the GPU, also installs a VSync event handler + ResetGraph( 0 ); + + // Set display and draw environment areas + // (display and draw areas must be separate, otherwise hello flicker) + SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + + // Enable draw area clear and dither processing + setRGB0( &db[0].draw, 63, 0, 127 ); + db[0].draw.isbg = 1; + db[0].draw.dtd = 1; + + + // Define the second set of display/draw environments + SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); + + setRGB0( &db[1].draw, 63, 0, 127 ); + db[1].draw.isbg = 1; + db[1].draw.dtd = 1; + + // Apply the drawing environment of the first double buffer + PutDrawEnv( &db[0].draw ); + + // Clear both ordering tables to make sure they are clean at the start + ClearOTagR( db[0].ot, OT_LEN ); + ClearOTagR( db[1].ot, OT_LEN ); + + // Set primitive pointer address + db_nextpri = db[0].p; + + // Set clip region + setRECT( &screen_clip, 0, 0, SCREEN_XRES, SCREEN_YRES ); + + + // Initialize the GTE + InitGeom(); + + // Set GTE offset (recommended method of centering) + gte_SetGeomOffset( CENTERX, CENTERY ); + + // Set screen depth (basically FOV control, W/2 works best) + gte_SetGeomScreen( CENTERX ); + + // Set light ambient color and light color matrix + gte_SetBackColor( 63, 63, 63 ); + gte_SetColorMatrix( &color_mtx ); + + + // Init BIOS pad driver and set pad buffers (buffers are updated + // automatically on every V-Blank) + InitPAD(&pad_buff[0][0], 34, &pad_buff[1][0], 34); + + // Start pad + StartPAD(); + + // Don't make pad driver acknowledge V-Blank IRQ (recommended) + ChangeClearPAD(0); + + // Load font and open a text stream + FntLoad(960, 0); + FntOpen(0, 8, 320, 216, 0, 100); + +} + +void display() { + + // Wait for GPU to finish drawing and vertical retrace + DrawSync( 0 ); + VSync( 0 ); + + // Swap buffers + db_active ^= 1; + db_nextpri = db[db_active].p; + + // Clear the OT of the next frame + ClearOTagR( db[db_active].ot, OT_LEN ); + + // Apply display/drawing environments + PutDrawEnv( &db[db_active].draw ); + PutDispEnv( &db[db_active].disp ); + + // Enable display + SetDispMask( 1 ); + + // Start drawing the OT of the last buffer + DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); + +} + diff --git a/examples/graphics/fpscam/makefile b/examples/graphics/fpscam/makefile new file mode 100644 index 0000000..339bb91 --- /dev/null +++ b/examples/graphics/fpscam/makefile @@ -0,0 +1,39 @@ +include ../../sdk-common.mk + +TARGET = fpscam.elf + +CFILES = $(notdir $(wildcard *.c)) +CPPFILES = $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) + +INCLUDE += +LIBDIRS += + +LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc + +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +CPPFLAGS = $(CFLAGS) -fno-exceptions +AFLAGS = -g -msoft-float +LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x + +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/graphics/gte/main.c b/examples/graphics/gte/main.c new file mode 100644 index 0000000..432ef95 --- /dev/null +++ b/examples/graphics/gte/main.c @@ -0,0 +1,313 @@ +/* + * LibPSn00b Example Programs + * + * GTE Graphics Example + * 2019 Meido-Tek Productions / PSn00bSDK Project + * + * Renders a spinning 3D cube with light source calculation + * using GTE macros. + * + * + * Example by Lameguy64 + * + * Changelog: + * + * Jan 26, 2019 - Initial version. + * + */ + +#include +#include +#include +#include + +/* OT and Packet Buffer sizes */ +#define OT_LEN 256 +#define PACKET_LEN 1024 + +/* Screen resolution */ +#define SCREEN_XRES 320 +#define SCREEN_YRES 240 + +/* Screen center position */ +#define CENTERX SCREEN_XRES>>1 +#define CENTERY SCREEN_YRES>>1 + + +/* Double buffer structure */ +typedef struct { + DISPENV disp; /* Display environment */ + DRAWENV draw; /* Drawing environment */ + int ot[OT_LEN]; /* Ordering table */ + char p[PACKET_LEN]; /* Packet buffer */ +} DB; + +/* Double buffer variables */ +DB db[2]; +int db_active = 0; +char *db_nextpri; + + +/* For easier handling of vertex indices */ +typedef struct { + short v0,v1,v2,v3; +} INDEX; + +/* Cube vertices */ +SVECTOR cube_verts[] = { + { -100, -100, -100, 0 }, + { 100, -100, -100, 0 }, + { -100, 100, -100, 0 }, + { 100, 100, -100, 0 }, + { 100, -100, 100, 0 }, + { -100, -100, 100, 0 }, + { 100, 100, 100, 0 }, + { -100, 100, 100, 0 } +}; + +/* Cube face normals */ +SVECTOR cube_norms[] = { + { 0, 0, -ONE, 0 }, + { 0, 0, ONE, 0 }, + { 0, -ONE, 0, 0 }, + { 0, ONE, 0, 0 }, + { -ONE, 0, 0, 0 }, + { ONE, 0, 0, 0 } +}; + +/* Cube vertex indices */ +INDEX cube_indices[] = { + { 0, 1, 2, 3 }, + { 4, 5, 6, 7 }, + { 5, 4, 0, 1 }, + { 6, 7, 3, 2 }, + { 0, 2, 5, 7 }, + { 3, 1, 6, 4 } +}; + +/* Number of faces of cube */ +#define CUBE_FACES 6 + + +/* Light color matrix */ +/* Each column represents the color matrix of each light source and is */ +/* used as material color when using gte_ncs() or multiplied by a */ +/* source color when using gte_nccs(). 4096 is 1.0 in this matrix */ +/* A column of zeroes disables the light source. */ +MATRIX color_mtx = { + ONE, 0, 0, /* Red */ + ONE, 0, 0, /* Green */ + ONE, 0, 0 /* Blue */ +}; + +/* Light matrix */ +/* Each row represents a vector direction of each light source. */ +/* An entire row of zeroes disables the light source. */ +MATRIX light_mtx = { + /* X, Y, Z */ + -2048 , -2048 , -2048, + 0 , 0 , 0, + 0 , 0 , 0 +}; + + +/* Function declarations */ +void init(); +void display(); + + +/* Main function */ +int main() { + + int i,p,xy_temp; + + SVECTOR rot = { 0 }; /* Rotation vector for Rotmatrix */ + VECTOR pos = { 0, 0, 400 }; /* Translation vector for TransMatrix */ + MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ + + POLY_F4 *pol4; /* Flat shaded quad primitive pointer */ + + + /* Init graphics and GTE */ + init(); + + + /* Main loop */ + while( 1 ) { + + /* Set rotation and translation to the matrix */ + RotMatrix( &rot, &mtx ); + TransMatrix( &mtx, &pos ); + + /* Multiply light matrix by rotation matrix so light source */ + /* won't appear relative to the model's rotation */ + MulMatrix0( &light_mtx, &mtx, &lmtx ); + + /* Set rotation and translation matrix */ + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + /* Set light matrix */ + gte_SetLightMatrix( &lmtx ); + + /* Make the cube SPEEN */ + rot.vx += 16; + rot.vz += 16; + + + /* Draw the cube */ + pol4 = (POLY_F4*)db_nextpri; + + for( i=0; i>2) > OT_LEN ) + continue; + + /* Initialize a quad primitive */ + setPolyF4( pol4 ); + + /* Set the projected vertices to the primitive */ + gte_stsxy0( &pol4->x0 ); + gte_stsxy1( &pol4->x1 ); + gte_stsxy2( &pol4->x2 ); + + /* Compute the last vertex and set the result */ + gte_ldv0( &cube_verts[cube_indices[i].v3] ); + gte_rtps(); + gte_stsxy( &pol4->x3 ); + + /* Load primitive color even though gte_ncs() doesn't use it. */ + /* This is so the GTE will output a color result with the */ + /* correct primitive code. */ + gte_ldrgb( &pol4->r0 ); + + /* Load the face normal */ + gte_ldv0( &cube_norms[i] ); + + /* Normal Color Single */ + gte_ncs(); + + /* Store result to the primitive */ + gte_strgb( &pol4->r0 ); + + /* Sort primitive to the ordering table */ + addPrim( db[db_active].ot+(p>>2), pol4 ); + + /* Advance to make another primitive */ + pol4++; + + } + + /* Update nextpri variable */ + /* (IMPORTANT if you plan to sort more primitives after this) */ + db_nextpri = (char*)pol4; + + /* Swap buffers and draw the primitives */ + display(); + + } + + return 0; + +} + +void init() { + + /* Reset the GPU, also installs a VSync event handler */ + ResetGraph( 0 ); + + /* Set display and draw environment areas */ + /* (display and draw areas must be separate, otherwise hello flicker) */ + SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + + /* Enable draw area clear and dither processing */ + setRGB0( &db[0].draw, 63, 0, 127 ); + db[0].draw.isbg = 1; + db[0].draw.dtd = 1; + + + /* Define the second set of display/draw environments */ + SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); + + setRGB0( &db[1].draw, 63, 0, 127 ); + db[1].draw.isbg = 1; + db[1].draw.dtd = 1; + + + /* Apply the drawing environment of the first double buffer */ + PutDrawEnv( &db[0].draw ); + + + /* Clear both ordering tables to make sure they are clean at the start */ + ClearOTagR( db[0].ot, OT_LEN ); + ClearOTagR( db[1].ot, OT_LEN ); + + /* Set primitive pointer address */ + db_nextpri = db[0].p; + + /* Initialize the GTE */ + InitGeom(); + + /* Set GTE offset (recommended method of centering) */ + gte_SetGeomOffset( CENTERX, CENTERY ); + + /* Set screen depth (basically FOV control, W/2 works best) */ + gte_SetGeomScreen( CENTERX ); + + /* Set light ambient color and light color matrix */ + gte_SetBackColor( 63, 63, 63 ); + gte_SetColorMatrix( &color_mtx ); + +} + +void display() { + + /* Wait for GPU to finish drawing and vertical retrace */ + DrawSync( 0 ); + VSync( 0 ); + + /* Swap buffers */ + db_active ^= 1; + db_nextpri = db[db_active].p; + + /* Clear the OT of the next frame */ + ClearOTagR( db[db_active].ot, OT_LEN ); + + /* Apply display/drawing environments */ + PutDrawEnv( &db[db_active].draw ); + PutDispEnv( &db[db_active].disp ); + + /* Enable display */ + SetDispMask( 1 ); + + /* Start drawing the OT of the last buffer */ + DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); + +} \ No newline at end of file diff --git a/examples/graphics/gte/makefile b/examples/graphics/gte/makefile new file mode 100644 index 0000000..8b3f81f --- /dev/null +++ b/examples/graphics/gte/makefile @@ -0,0 +1,39 @@ +include ../../sdk-common.mk + +TARGET = gte.elf + +CFILES = $(notdir $(wildcard *.c)) +CPPFILES = $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) + +INCLUDE += +LIBDIRS += + +LIBS = -lc -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc + +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +CPPFLAGS = $(CFLAGS) -fno-exceptions +AFLAGS = -g -msoft-float +LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x + +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/graphics/render2tex/blendpattern-16c.png b/examples/graphics/render2tex/blendpattern-16c.png new file mode 100644 index 0000000..74ac945 Binary files /dev/null and b/examples/graphics/render2tex/blendpattern-16c.png differ diff --git a/examples/graphics/render2tex/blendpattern-16c.tim b/examples/graphics/render2tex/blendpattern-16c.tim new file mode 100644 index 0000000..2fff580 Binary files /dev/null and b/examples/graphics/render2tex/blendpattern-16c.tim differ diff --git a/examples/graphics/render2tex/blendpattern.png b/examples/graphics/render2tex/blendpattern.png new file mode 100644 index 0000000..49af62c Binary files /dev/null and b/examples/graphics/render2tex/blendpattern.png differ diff --git a/examples/graphics/render2tex/main.c b/examples/graphics/render2tex/main.c new file mode 100644 index 0000000..6ae450a --- /dev/null +++ b/examples/graphics/render2tex/main.c @@ -0,0 +1,649 @@ +/* + * LibPSn00b Example Programs + * + * Off-screen Render to Texture Example + * 2019 Meido-Tek Productions / PSn00bSDK Project + * + * Demonstrates quick render to texture for multi-texture style effects, + * view screens and more. This example also shows how to use multiple + * ordering tables and chaining them together so it can all be rendered + * with a single DrawOTag() call. + * + * Example by Lameguy64 + * + * Changelog: + * + * Oct 26, 2019 - Initial version. + * + */ + +#include +#include +#include +#include + + +/* OT and Packet Buffer sizes */ +#define OT_LEN 256 +#define PACKET_LEN 1024 + + +/* Screen resolution */ +/* (note: display/draw code is hardcoded for double buffer) */ +#define SCREEN_XRES 320 +#define SCREEN_YRES 240 + + +/* Screen center position */ +#define CENTERX SCREEN_XRES>>1 +#define CENTERY SCREEN_YRES>>1 + + +/* Double buffer structure */ +typedef struct DB +{ + DISPENV disp; /* Display environment */ + DRAWENV draw; /* Drawing environment */ + int ot[OT_LEN]; /* Main ordering table */ + int sub_ot[2][4]; /* Second ordering table for r2t stuff */ + char p[PACKET_LEN]; /* Packet buffer */ +} DB; + + +/* Double buffer variables */ +DB db[2]; +int db_active = 0; +char *db_nextpri; + + +/* For easier handling of vertex indices */ +typedef struct { + short v0,v1,v2,v3; +} INDEX; + +/* Cube vertices */ +SVECTOR cube_verts[] = { + { -100, -100, -100, 0 }, + { 100, -100, -100, 0 }, + { -100, 100, -100, 0 }, + { 100, 100, -100, 0 }, + { 100, -100, 100, 0 }, + { -100, -100, 100, 0 }, + { 100, 100, 100, 0 }, + { -100, 100, 100, 0 } +}; + +/* Cube face normals */ +SVECTOR cube_norms[] = { + { 0, 0, -ONE, 0 }, + { 0, -ONE, 0, 0 }, + { 0, 0, ONE, 0 }, + { 0, ONE, 0, 0 }, + { ONE, 0, 0, 0 }, + { -ONE, 0, 0, 0 } +}; + +/* Cube vertex indices */ +INDEX cube_indices[] = { + { 0, 1, 2, 3 }, + { 5, 4, 0, 1 }, + { 4, 5, 6, 7 }, + { 6, 7, 3, 2 }, + { 3, 1, 6, 4 }, + { 0, 2, 5, 7 } +}; + +/* Number of cube faces */ +#define CUBE_FACES 6 + +/* Light color matrix */ +MATRIX color_mtx = { + ONE, 0, 0, /* Red */ + ONE, 0, 0, /* Green */ + ONE, 0, 0 /* Blue */ +}; + +/* Light matrix */ +MATRIX light_mtx = { + /* X, Y, Z */ + -2048 , -2048 , -2048, + 0 , 0 , 0, + 0 , 0 , 0 +}; + + +/* Reference texture data */ +extern int tim_blendpattern[]; + + +/* TPage and CLUT values */ +unsigned short rendertex_tpage; /* For the render to texture cube */ +unsigned short bpattern_tpage; /* For the scrolling blending pattern */ +unsigned short bpattern_clut; + + +/* Function declarations */ +void init(); +void display(); + +/* This function sorts a cube that is drawn + * to an offscreen area specified by *area */ +void sort_cube(int *ot, RECT *area); +void sort_multitex(int *ot, RECT *area, int count); + +/* Main function */ +int main() { + + int i,p,xy_temp; + int count = 0; + + SVECTOR rot = { 0 }; /* Rotation vector for Rotmatrix */ + VECTOR pos = { 0, 0, 400 }; /* Translation vector for TransMatrix */ + MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ + + VECTOR spos = { 0, 0, 250 }; + SVECTOR srot = { 0 }; + + RECT texarea,area,dtexarea; + RECT cubearea; + + POLY_FT4 *pol4; /* Flat shaded quad primitive pointer */ + + + /* Init graphics and GTE */ + init(); + + setRECT(&area, 704, 0, 64, 64); + setRECT(&cubearea, 704, 64, 64, 64); + + setRECT(&texarea, 0, 0, 64>>3, 64>>3); + setRECT(&dtexarea, 0, 0, 0, 0); + + rendertex_tpage = getTPage(2, 0, area.x, area.y); + + /* Main loop */ + while( 1 ) { + + /* Sort multi-texture stuff */ + sort_multitex(db[db_active].ot+(OT_LEN-1), &area, count); + + /* Matrix stuff for render to texture cube */ + RotMatrix( &srot, &mtx ); + TransMatrix( &mtx, &spos ); + + MulMatrix0( &light_mtx, &mtx, &lmtx ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + gte_SetLightMatrix( &lmtx ); + + /* Reduce FOV to fit in area and sort cube */ + gte_SetGeomScreen(32); + + sort_cube(db[db_active].ot+(OT_LEN-1), &cubearea); + + gte_SetGeomScreen(CENTERX); + + + /* Set rotation and translation to the matrix */ + RotMatrix( &rot, &mtx ); + TransMatrix( &mtx, &pos ); + + /* Multiply light matrix by rotation matrix so light source */ + /* won't appear relative to the model's rotation */ + MulMatrix0( &light_mtx, &mtx, &lmtx ); + + /* Set rotation and translation matrix */ + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + /* Set light matrix */ + gte_SetLightMatrix( &lmtx ); + + /* Make the cube SPEEN */ + rot.vx += 4; + rot.vz += 4; + + srot.vx += 8; + srot.vy += 8; + srot.vz -= 8; + + /* Draw the cube */ + pol4 = (POLY_FT4*)db_nextpri; + + for( i=0; i>2) > OT_LEN ) + continue; + + /* Initialize a quad primitive */ + setPolyFT4( pol4 ); + + /* Set the projected vertices to the primitive */ + gte_stsxy0( &pol4->x0 ); + gte_stsxy1( &pol4->x1 ); + gte_stsxy2( &pol4->x2 ); + + /* Compute the last vertex and set the result */ + gte_ldv0( &cube_verts[cube_indices[i].v3] ); + gte_rtps(); + gte_stsxy( &pol4->x3 ); + + /* Load primitive color even though gte_ncs() doesn't use it. */ + /* This is so the GTE will output a color result with the */ + /* correct primitive code. */ + gte_ldrgb( &pol4->r0 ); + + /* Load the face normal */ + gte_ldv0( &cube_norms[i] ); + + /* Normal Color Single */ + gte_ncs(); + + /* Store result to the primitive */ + gte_strgb( &pol4->r0 ); + + // Map to render to texture texture + pol4->tpage = rendertex_tpage; + if( (i&0x1) == 0 ) + setUVWH(pol4, 0, 0, 63, 63); + else + setUVWH(pol4, 0, 64, 63, 63); + + + /* Sort primitive to the ordering table */ + addPrim( db[db_active].ot+(p>>2), pol4 ); + + /* Advance to make another primitive */ + pol4++; + + } + + /* Update nextpri variable */ + /* (IMPORTANT if you plan to sort more primitives after this) */ + db_nextpri = (char*)pol4; + + /* Swap buffers and draw the primitives */ + display(); + + count++; + + } + + return 0; + +} + +void init() { + + TIM_IMAGE tim; + + /* Reset the GPU, also installs a VSync event handler */ + ResetGraph( 0 ); + + /* Set display and draw environment areas */ + /* (display and draw areas must be separate, otherwise hello flicker) */ + SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + + /* Enable draw area clear and dither processing */ + setRGB0( &db[0].draw, 63, 0, 127 ); + db[0].draw.isbg = 1; + db[0].draw.dtd = 1; + + + /* Define the second set of display/draw environments */ + SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); + + setRGB0( &db[1].draw, 63, 0, 127 ); + db[1].draw.isbg = 1; + db[1].draw.dtd = 1; + + + /* Apply the drawing environment of the first double buffer */ + PutDrawEnv( &db[0].draw ); + + + /* Clear both ordering tables to make sure they are clean at the start */ + ClearOTagR( db[0].ot, OT_LEN ); + ClearOTagR( db[1].ot, OT_LEN ); + ClearOTagR( db[0].sub_ot[0], 4 ); + ClearOTagR( db[0].sub_ot[1], 4 ); + ClearOTagR( db[1].sub_ot[0], 4 ); + ClearOTagR( db[1].sub_ot[1], 4 ); + + /* Set primitive pointer address */ + db_nextpri = db[0].p; + + /* Initialize the GTE */ + InitGeom(); + + /* Set GTE offset (recommended method of centering) */ + gte_SetGeomOffset( CENTERX, CENTERY ); + + /* Set screen depth (basically FOV control, W/2 works best) */ + gte_SetGeomScreen( CENTERX ); + + /* Set light ambient color and light color matrix */ + gte_SetBackColor( 63, 63, 63 ); + gte_SetColorMatrix( &color_mtx ); + + GetTimInfo(tim_blendpattern, &tim); + if( tim.mode & 0x8 ) + { + LoadImage( tim.crect, tim.caddr ); /* Upload CLUT if present */ + } + LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */ + + bpattern_tpage = getTPage(0, 1, tim.prect->x, tim.prect->y); + bpattern_clut = getClut(tim.crect->x, tim.crect->y); + +} + +void display() { + + /* Wait for GPU to finish drawing and vertical retrace */ + DrawSync( 0 ); + VSync( 0 ); + + /* Swap buffers */ + db_active ^= 1; + db_nextpri = db[db_active].p; + + /* Clear the OT of the next frame */ + ClearOTagR( db[db_active].ot, OT_LEN ); + ClearOTagR( db[db_active].sub_ot[0], 4 ); + ClearOTagR( db[db_active].sub_ot[1], 4 ); + + /* Apply display/drawing environments */ + PutDrawEnv( &db[db_active].draw ); + PutDispEnv( &db[db_active].disp ); + + /* Enable display */ + SetDispMask( 1 ); + + /* Start drawing the OT of the last buffer */ + DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); + +} + +void sort_multitex(int *ot, RECT *area, int count) +{ + DR_TPAGE *ptpage; + FILL *pfill; + DR_AREA *parea; + DR_TWIN *ptwin; + DR_OFFSET *poffs; + + SPRT *psprt; + + /* Texture window constraint */ + /* (coordinates specified in units of 8 pixels) */ + RECT texwindow = { 0, 0, 64>>3, 64>>3 }; + + /* Sort the sub OT to the specified OT level */ + addPrims( + ot, /* Target OT */ + db[db_active].sub_ot[0]+3, /* Start of OT to sort */ + db[db_active].sub_ot[0]); /* End of OT to sort */ + + + /* Sort a FILL primitive to clear the off-screen area */ + pfill = (FILL*)db_nextpri; + setFill(pfill); + setXY0(pfill, area->x, area->y); + setWH(pfill, 64, 64); + setRGB0(pfill, 0, 0, 0); + addPrim(db[db_active].sub_ot[0]+3, pfill); + db_nextpri += sizeof(FILL); + + + /* Sort draw area primitives to set the drawing target */ + parea = (DR_AREA*)db_nextpri; + + setDrawArea(parea, area); /* Sets to off-screen area */ + addPrim(db[db_active].sub_ot[0]+3, parea); + parea++; + + setDrawArea(parea, /* Reverts to draw area */ + &db[1-db_active].draw.clip); + addPrim(db[db_active].sub_ot[0]+1, parea); + parea++; + db_nextpri = (char*)parea; + + + /* Sort offset primitives to set the drawing offset to the target */ + poffs = (DR_OFFSET*)db_nextpri; + + setDrawOffset(poffs, area->x, area->y); /* Sets to off-screen area */ + addPrim(db[db_active].sub_ot[0]+3, poffs); + poffs++; + + setDrawOffset(poffs, /* Reverts to draw area */ + db[1-db_active].draw.clip.x, + db[1-db_active].draw.clip.y); + addPrim(db[db_active].sub_ot[0]+1, poffs); + poffs++; + db_nextpri = (char*)poffs; + + + /* This sets the active texture page for the SPRT primitives */ + ptpage = (DR_TPAGE*)db_nextpri; + setDrawTPage(ptpage, 1, 0, bpattern_tpage); + addPrim(db[db_active].sub_ot[0]+3, ptpage); + ptpage++; + db_nextpri = (char*)ptpage; + + + /* Sort a DR_TWIN primitive to wrap texture coordinates to 64x64 */ + ptwin = (DR_TWIN*)db_nextpri; + + setTexWindow(ptwin, &texwindow); /* Set window constraint */ + addPrim(db[db_active].sub_ot[0]+3, ptwin); + ptwin++; + + texwindow.w = 0; /* Clear window constraint */ + texwindow.h = 0; + setTexWindow(ptwin, &texwindow); + addPrim(db[db_active].sub_ot[0]+1, ptwin); + ptwin++; + db_nextpri = (char*)ptwin; + + + /* Sort blending and scrolling sprites layering over one another */ + psprt = (SPRT*)db_nextpri; + + /* Sort pattern in green scrolling up-left */ + setSprt(psprt); + setSemiTrans(psprt, 1); + setXY0(psprt, 0, 0); + setWH(psprt, 64, 64); + setUV0(psprt, (count>>1)&0x3F, count&0x3F); + setRGB0(psprt, 0, 91, 0); + psprt->clut = bpattern_clut; + addPrim(db[db_active].sub_ot[0]+1, psprt); + psprt++; + + /* Sort pattern in blue scrolling up-right*/ + setSprt(psprt); + setSemiTrans(psprt, 1); + setXY0(psprt, 0, 0); + setWH(psprt, 64, 64); + setUV0(psprt, (-count>>1)&0x3F, (count>>1)&0x3F); + setRGB0(psprt, 0, 0, 91); + psprt->clut = bpattern_clut; + addPrim(db[db_active].sub_ot[0]+1, psprt); + psprt++; + + /* Sort pattern in red scrolling down-right */ + setSprt(psprt); + setSemiTrans(psprt, 1); + setXY0(psprt, 0, 0); + setWH(psprt, 64, 64); + setUV0(psprt, (-count>>1)&0x3F, (-count>>1)&0x3F); + setRGB0(psprt, 91, 0, 0); + psprt->clut = bpattern_clut; + addPrim(db[db_active].sub_ot[0]+1, psprt); + psprt++; + + /* Sort pattern in grey scrolling up-left */ + setSprt(psprt); + setXY0(psprt, 0, 0); + setWH(psprt, 64, 64); + setUV0(psprt, count&0x3F, (count>>1)&0x3F); + setRGB0(psprt, 64, 64, 64); + psprt->clut = bpattern_clut; + addPrim(db[db_active].sub_ot[0]+1, psprt); + psprt++; + + db_nextpri = (char*)psprt; + +} + +void sort_cube(int *ot, RECT *area) +{ + int i,p; + POLY_FT4* pol4; + FILL* pfill; + DR_AREA* parea; + DR_OFFSET* poffs; + + addPrims( + ot, + db[db_active].sub_ot[1]+3, + db[db_active].sub_ot[1]); + + pfill = (FILL*)db_nextpri; + setFill(pfill); + setXY0(pfill, area->x, area->y); + setWH(pfill, 64, 64); + setRGB0(pfill, 128, 91, 0); + addPrim(db[db_active].sub_ot[1]+3, pfill); + db_nextpri += sizeof(FILL); + + parea = (DR_AREA*)db_nextpri; + setDrawArea(parea, area); + addPrim(db[db_active].sub_ot[1]+3, parea); + parea++; + setDrawArea(parea, &db[1-db_active].draw.clip); + addPrim(db[db_active].sub_ot[1]+1, parea); + parea++; + db_nextpri = (char*)parea; + + poffs = (DR_OFFSET*)db_nextpri; + setDrawOffset(poffs, area->x, area->y); + addPrim(db[db_active].sub_ot[1]+3, poffs); + poffs++; + setDrawOffset(poffs, db[1-db_active].draw.clip.x, db[1-db_active].draw.clip.y); + addPrim(db[db_active].sub_ot[1]+1, poffs); + poffs++; + db_nextpri = (char*)poffs; + + + gte_SetGeomOffset(32, 32); + + // Sort the cube + pol4 = (POLY_FT4*)db_nextpri; + + for( i=0; i>6) <= 0) || ((p>>6) >= 4) ) + continue;*/ + + // Initialize a quad primitive + setPolyFT4( pol4 ); + + // Set the projected vertices to the primitive + gte_stsxy0( &pol4->x0 ); + gte_stsxy1( &pol4->x1 ); + gte_stsxy2( &pol4->x2 ); + + // Compute the last vertex and set the result + gte_ldv0( &cube_verts[cube_indices[i].v3] ); + gte_rtps(); + gte_stsxy( &pol4->x3 ); + + // Load primitive color even though gte_ncs() doesn't use it. + // This is so the GTE will output a color result with the + // correct primitive code. + gte_ldrgb( &pol4->r0 ); + + // Load the face normal + gte_ldv0( &cube_norms[i] ); + + // Normal Color Single + gte_ncs(); + + // Store result to the primitive + gte_strgb( &pol4->r0 ); + + gte_avsz4(); + gte_stotz( &p ); + + pol4->tpage = rendertex_tpage; + setUVWH(pol4, 0, 0, 63, 63); + + // Sort primitive to the ordering table + addPrim( db[db_active].sub_ot[1]+1, pol4 ); + + // Advance to make another primitive + pol4++; + + } + + // Update nextpri + db_nextpri = (char*)pol4; + + gte_SetGeomOffset(CENTERX, CENTERY); +} \ No newline at end of file diff --git a/examples/graphics/render2tex/makefile b/examples/graphics/render2tex/makefile new file mode 100644 index 0000000..aaa3b1d --- /dev/null +++ b/examples/graphics/render2tex/makefile @@ -0,0 +1,39 @@ +include ../../sdk-common.mk + +TARGET = render2tex.elf + +CFILES = $(notdir $(wildcard *.c)) +CPPFILES = $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) + +INCLUDE += +LIBDIRS += + +LIBS = -lc -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lgcc + +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +CPPFLAGS = $(CFLAGS) -fno-exceptions +AFLAGS = -g -msoft-float +LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x + +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/graphics/render2tex/texture.s b/examples/graphics/render2tex/texture.s new file mode 100644 index 0000000..e786dce --- /dev/null +++ b/examples/graphics/render2tex/texture.s @@ -0,0 +1,9 @@ +# Assembler file for including the texture file in a more elegant manner + +.section .data + +.global tim_blendpattern +.type tim_blendpattern, @object +tim_blendpattern: + .incbin "blendpattern-16c.tim" + \ No newline at end of file diff --git a/examples/graphics/rgb24/bunpattern.tim b/examples/graphics/rgb24/bunpattern.tim new file mode 100644 index 0000000..f233453 Binary files /dev/null and b/examples/graphics/rgb24/bunpattern.tim differ diff --git a/examples/graphics/rgb24/main.c b/examples/graphics/rgb24/main.c new file mode 100644 index 0000000..9f1a647 --- /dev/null +++ b/examples/graphics/rgb24/main.c @@ -0,0 +1,52 @@ +/* LibPSn00b Example Programs + * Part of the PSn00bSDK Project + * + * RGB24 Example by Lameguy64 + * + * + * This example demonstrates the 24-bit color mode of the PS1. This mode is + * not practical for gameplay as the GPU can only draw graphics primitives + * in 16-bit color depth so this feature would normally be used only for + * fullscreen graphic illustrations or FMV sequences. + * + * + * Changelog: + * + * 05-03-2019 - Initial version. + * + */ + +#include +#include +#include + +// So data from tim.s can be accessed +extern unsigned int tim_image[]; + +int main() { + + DISPENV disp; + TIM_IMAGE tim; + + // Reset GPU + ResetGraph(0); + + // Setup 640x480 24-bit video mode + SetDefDispEnv(&disp, 0, 0, 640, 480); + disp.isrgb24 = 1; + disp.isinter = 1; + + // Apply and enable display + PutDispEnv(&disp); + SetDispMask(1); + + // Upload image to VRAM + GetTimInfo(tim_image, &tim); + LoadImage(tim.prect, tim.paddr); + DrawSync(0); + + while(1) { + } + + return 0; +} \ No newline at end of file diff --git a/examples/graphics/rgb24/makefile b/examples/graphics/rgb24/makefile new file mode 100644 index 0000000..61ef24f --- /dev/null +++ b/examples/graphics/rgb24/makefile @@ -0,0 +1,41 @@ +include ../../sdk-common.mk + +TARGET = rgb24.elf + +CFILES = $(notdir $(wildcard *.c)) +CPPFILES = $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) + +INCLUDE += +LIBDIRS += + +LIBS = -lpsxgpu -lpsxapi -lc + +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +CPPFLAGS = $(CFLAGS) -fno-exceptions +AFLAGS = -g -msoft-float +LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x + +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.tim + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/graphics/rgb24/tim.s b/examples/graphics/rgb24/tim.s new file mode 100644 index 0000000..a4432d9 --- /dev/null +++ b/examples/graphics/rgb24/tim.s @@ -0,0 +1,7 @@ +.section .data + +.global tim_image +.type tim_image, @object +tim_image: + .incbin "bunpattern.tim" + \ No newline at end of file diff --git a/examples/gte/main.c b/examples/gte/main.c deleted file mode 100644 index 432ef95..0000000 --- a/examples/gte/main.c +++ /dev/null @@ -1,313 +0,0 @@ -/* - * LibPSn00b Example Programs - * - * GTE Graphics Example - * 2019 Meido-Tek Productions / PSn00bSDK Project - * - * Renders a spinning 3D cube with light source calculation - * using GTE macros. - * - * - * Example by Lameguy64 - * - * Changelog: - * - * Jan 26, 2019 - Initial version. - * - */ - -#include -#include -#include -#include - -/* OT and Packet Buffer sizes */ -#define OT_LEN 256 -#define PACKET_LEN 1024 - -/* Screen resolution */ -#define SCREEN_XRES 320 -#define SCREEN_YRES 240 - -/* Screen center position */ -#define CENTERX SCREEN_XRES>>1 -#define CENTERY SCREEN_YRES>>1 - - -/* Double buffer structure */ -typedef struct { - DISPENV disp; /* Display environment */ - DRAWENV draw; /* Drawing environment */ - int ot[OT_LEN]; /* Ordering table */ - char p[PACKET_LEN]; /* Packet buffer */ -} DB; - -/* Double buffer variables */ -DB db[2]; -int db_active = 0; -char *db_nextpri; - - -/* For easier handling of vertex indices */ -typedef struct { - short v0,v1,v2,v3; -} INDEX; - -/* Cube vertices */ -SVECTOR cube_verts[] = { - { -100, -100, -100, 0 }, - { 100, -100, -100, 0 }, - { -100, 100, -100, 0 }, - { 100, 100, -100, 0 }, - { 100, -100, 100, 0 }, - { -100, -100, 100, 0 }, - { 100, 100, 100, 0 }, - { -100, 100, 100, 0 } -}; - -/* Cube face normals */ -SVECTOR cube_norms[] = { - { 0, 0, -ONE, 0 }, - { 0, 0, ONE, 0 }, - { 0, -ONE, 0, 0 }, - { 0, ONE, 0, 0 }, - { -ONE, 0, 0, 0 }, - { ONE, 0, 0, 0 } -}; - -/* Cube vertex indices */ -INDEX cube_indices[] = { - { 0, 1, 2, 3 }, - { 4, 5, 6, 7 }, - { 5, 4, 0, 1 }, - { 6, 7, 3, 2 }, - { 0, 2, 5, 7 }, - { 3, 1, 6, 4 } -}; - -/* Number of faces of cube */ -#define CUBE_FACES 6 - - -/* Light color matrix */ -/* Each column represents the color matrix of each light source and is */ -/* used as material color when using gte_ncs() or multiplied by a */ -/* source color when using gte_nccs(). 4096 is 1.0 in this matrix */ -/* A column of zeroes disables the light source. */ -MATRIX color_mtx = { - ONE, 0, 0, /* Red */ - ONE, 0, 0, /* Green */ - ONE, 0, 0 /* Blue */ -}; - -/* Light matrix */ -/* Each row represents a vector direction of each light source. */ -/* An entire row of zeroes disables the light source. */ -MATRIX light_mtx = { - /* X, Y, Z */ - -2048 , -2048 , -2048, - 0 , 0 , 0, - 0 , 0 , 0 -}; - - -/* Function declarations */ -void init(); -void display(); - - -/* Main function */ -int main() { - - int i,p,xy_temp; - - SVECTOR rot = { 0 }; /* Rotation vector for Rotmatrix */ - VECTOR pos = { 0, 0, 400 }; /* Translation vector for TransMatrix */ - MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ - - POLY_F4 *pol4; /* Flat shaded quad primitive pointer */ - - - /* Init graphics and GTE */ - init(); - - - /* Main loop */ - while( 1 ) { - - /* Set rotation and translation to the matrix */ - RotMatrix( &rot, &mtx ); - TransMatrix( &mtx, &pos ); - - /* Multiply light matrix by rotation matrix so light source */ - /* won't appear relative to the model's rotation */ - MulMatrix0( &light_mtx, &mtx, &lmtx ); - - /* Set rotation and translation matrix */ - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - /* Set light matrix */ - gte_SetLightMatrix( &lmtx ); - - /* Make the cube SPEEN */ - rot.vx += 16; - rot.vz += 16; - - - /* Draw the cube */ - pol4 = (POLY_F4*)db_nextpri; - - for( i=0; i>2) > OT_LEN ) - continue; - - /* Initialize a quad primitive */ - setPolyF4( pol4 ); - - /* Set the projected vertices to the primitive */ - gte_stsxy0( &pol4->x0 ); - gte_stsxy1( &pol4->x1 ); - gte_stsxy2( &pol4->x2 ); - - /* Compute the last vertex and set the result */ - gte_ldv0( &cube_verts[cube_indices[i].v3] ); - gte_rtps(); - gte_stsxy( &pol4->x3 ); - - /* Load primitive color even though gte_ncs() doesn't use it. */ - /* This is so the GTE will output a color result with the */ - /* correct primitive code. */ - gte_ldrgb( &pol4->r0 ); - - /* Load the face normal */ - gte_ldv0( &cube_norms[i] ); - - /* Normal Color Single */ - gte_ncs(); - - /* Store result to the primitive */ - gte_strgb( &pol4->r0 ); - - /* Sort primitive to the ordering table */ - addPrim( db[db_active].ot+(p>>2), pol4 ); - - /* Advance to make another primitive */ - pol4++; - - } - - /* Update nextpri variable */ - /* (IMPORTANT if you plan to sort more primitives after this) */ - db_nextpri = (char*)pol4; - - /* Swap buffers and draw the primitives */ - display(); - - } - - return 0; - -} - -void init() { - - /* Reset the GPU, also installs a VSync event handler */ - ResetGraph( 0 ); - - /* Set display and draw environment areas */ - /* (display and draw areas must be separate, otherwise hello flicker) */ - SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - - /* Enable draw area clear and dither processing */ - setRGB0( &db[0].draw, 63, 0, 127 ); - db[0].draw.isbg = 1; - db[0].draw.dtd = 1; - - - /* Define the second set of display/draw environments */ - SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); - - setRGB0( &db[1].draw, 63, 0, 127 ); - db[1].draw.isbg = 1; - db[1].draw.dtd = 1; - - - /* Apply the drawing environment of the first double buffer */ - PutDrawEnv( &db[0].draw ); - - - /* Clear both ordering tables to make sure they are clean at the start */ - ClearOTagR( db[0].ot, OT_LEN ); - ClearOTagR( db[1].ot, OT_LEN ); - - /* Set primitive pointer address */ - db_nextpri = db[0].p; - - /* Initialize the GTE */ - InitGeom(); - - /* Set GTE offset (recommended method of centering) */ - gte_SetGeomOffset( CENTERX, CENTERY ); - - /* Set screen depth (basically FOV control, W/2 works best) */ - gte_SetGeomScreen( CENTERX ); - - /* Set light ambient color and light color matrix */ - gte_SetBackColor( 63, 63, 63 ); - gte_SetColorMatrix( &color_mtx ); - -} - -void display() { - - /* Wait for GPU to finish drawing and vertical retrace */ - DrawSync( 0 ); - VSync( 0 ); - - /* Swap buffers */ - db_active ^= 1; - db_nextpri = db[db_active].p; - - /* Clear the OT of the next frame */ - ClearOTagR( db[db_active].ot, OT_LEN ); - - /* Apply display/drawing environments */ - PutDrawEnv( &db[db_active].draw ); - PutDispEnv( &db[db_active].disp ); - - /* Enable display */ - SetDispMask( 1 ); - - /* Start drawing the OT of the last buffer */ - DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); - -} \ No newline at end of file diff --git a/examples/gte/makefile b/examples/gte/makefile deleted file mode 100644 index 2be2374..0000000 --- a/examples/gte/makefile +++ /dev/null @@ -1,39 +0,0 @@ -include ../sdk-common.mk - -TARGET = gte.elf - -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) - -INCLUDE += -LIBDIRS += - -LIBS = -lc -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc - -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x - -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -AS = $(PREFIX)as -LD = $(PREFIX)ld - -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/hello/main.c b/examples/hello/main.c deleted file mode 100644 index 1f02f0b..0000000 --- a/examples/hello/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * LibPSn00b Example Programs - * - * Hello World Example - * 2019-2020 Meido-Tek Productions / PSn00bSDK Project - * - * The obligatory hello world example normally included in nearly every - * SDK package. This example should also get you started in how to manage - * the display using psxgpu. - * - * Example by Lameguy64 - * - * - * Changelog: - * - * January 1, 2020 - Initial version - */ - -#include -#include -#include -#include -#include - - -// Define display/draw environments for double buffering -DISPENV disp[2]; -DRAWENV draw[2]; -int db; - - -// Init function -void init(void) -{ - // This not only resets the GPU but it also installs the library's - // ISR subsystem to the kernel - ResetGraph(0); - - // Define display environments, first on top and second on bottom - SetDefDispEnv(&disp[0], 0, 0, 320, 240); - SetDefDispEnv(&disp[1], 0, 240, 320, 240); - - // Define drawing environments, first on bottom and second on top - SetDefDrawEnv(&draw[0], 0, 240, 320, 240); - SetDefDrawEnv(&draw[1], 0, 0, 320, 240); - - // Set and enable clear color - setRGB0(&draw[0], 0, 96, 0); - setRGB0(&draw[1], 0, 96, 0); - draw[0].isbg = 1; - draw[1].isbg = 1; - - // Clear double buffer counter - db = 0; - - // Apply the GPU environments - PutDispEnv(&disp[db]); - PutDrawEnv(&draw[db]); - - // Load test font - FntLoad(960, 0); - - // Open up a test font text stream of 100 characters - FntOpen(0, 8, 320, 224, 0, 100); -} - -// Display function -void display(void) -{ - // Flip buffer index - db = !db; - - // Wait for all drawing to complete - DrawSync(0); - - // Wait for vertical sync to cap the logic to 60fps (or 50 in PAL mode) - // and prevent screen tearing - VSync(0); - - // Switch pages - PutDispEnv(&disp[db]); - PutDrawEnv(&draw[db]); - - // Enable display output, ResetGraph() disables it by default - SetDispMask(1); - -} - -// Main function, program entrypoint -int main(int argc, const char *argv[]) -{ - int counter; - - // Init stuff - init(); - - // Main loop - counter = 0; - while(1) - { - - // Print the obligatory hello world and counter to show that the - // program isn't locking up to the last created text stream - FntPrint(-1, "HELLO WORLD\n"); - FntPrint(-1, "COUNTER=%d\n", counter); - - // Draw the last created text stream - FntFlush(-1); - - // Update display - display(); - - // Increment the counter - counter++; - } - - return 0; -} diff --git a/examples/hello/makefile b/examples/hello/makefile deleted file mode 100644 index 77edaa7..0000000 --- a/examples/hello/makefile +++ /dev/null @@ -1,60 +0,0 @@ -include ../sdk-common.mk - -# Project target name -TARGET = hello.elf - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Determine object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.o)) \ - $(addprefix build/,$(AFILES:.s=.o)) - -# Project specific include and library directories -# (use -I for include dirs, -L for library dirs) -INCLUDE += -LIBDIRS += - -# Libraries to link -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc - -# C compiler flags -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections - -# C++ compiler flags -CPPFLAGS = $(CFLAGS) -fno-exceptions - -# Assembler flags -AFLAGS = -g -msoft-float - -# Linker flags -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x - -# Toolchain programs -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -AS = $(PREFIX)as -LD = $(PREFIX)ld - -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/lowlevel/cartrom/bios.inc b/examples/lowlevel/cartrom/bios.inc new file mode 100644 index 0000000..1c0201d --- /dev/null +++ b/examples/lowlevel/cartrom/bios.inc @@ -0,0 +1,67 @@ +printf: + addiu $t2, $0, 0xA0 + jr $t2 + addiu $t1, $0, 0x3F + +atoi: + addiu $t2, $0, 0xA0 + jr $t2 + addiu $t1, $0, 0x10 + +toupper: + addiu $t2, $0, 0xA0 + jr $t2 + addiu $t1, $0, 0x25 + +open: + addiu $t2, $0, 0xB0 + jr $t2 + addiu $t1, $0, 0x32 + +read: + addiu $t2, $0, 0xB0 + jr $t2 + addiu $t1, $0, 0x34 + +close: + addiu $t2, $0, 0xB0 + jr $t2 + addiu $t1, $0, 0x36 + +_96_init: + addiu $t2, $0, 0xA0 + jr $t2 + addiu $t1, $0, 0x71 + +LoadExe: + addiu $t2, $0, 0xA0 + jr $t2 + addiu $t1, $0, 0x42 + +DoExec: + addiu $t2, $0, 0xA0 + jr $t2 + addiu $t1, $0, 0x43 + +SetConf: + addiu $t2, $0, 0xA0 + jr $t2 + addiu $t1, $0, 0x9C + +SetDefaultExitFromException: + addiu $t2, $0, 0xB0 + jr $t2 + addiu $t1, $0, 0x18 + +EnterCriticalSection: + addiu $a0, $0, 1 + syscall 0 + jr $ra + nop + +ExitCriticalSection: + addiu $a0, $0, 2 + syscall 0 + jr $ra + nop + \ No newline at end of file diff --git a/examples/lowlevel/cartrom/cop0.inc b/examples/lowlevel/cartrom/cop0.inc new file mode 100644 index 0000000..620fa44 --- /dev/null +++ b/examples/lowlevel/cartrom/cop0.inc @@ -0,0 +1,11 @@ +.set BPC, $3 +.set BDA, $5 +.set JUMPDEST, $6 +.set DCIC, $7 +.set BADVADDR, $8 +.set BDAM, $9 +.set BPCM, $11 +.set SR, $12 +.set CAUSE, $13 +.set EPC, $14 +.set PRID, $15 diff --git a/examples/lowlevel/cartrom/makefile b/examples/lowlevel/cartrom/makefile new file mode 100644 index 0000000..2434685 --- /dev/null +++ b/examples/lowlevel/cartrom/makefile @@ -0,0 +1,14 @@ +PREFIX = mipsel-unknown-elf- + +CC = $(PREFIX)gcc +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: rom.o + $(LD) --oformat binary -T rom.ld -o cartrom.rom rom.o + +%.o: %.s + $(AS) -msoft-float --warn $< -o $@ + +clean: + rm -f rom.o cartrom.rom \ No newline at end of file diff --git a/examples/lowlevel/cartrom/parse.inc b/examples/lowlevel/cartrom/parse.inc new file mode 100644 index 0000000..b1190f7 --- /dev/null +++ b/examples/lowlevel/cartrom/parse.inc @@ -0,0 +1,113 @@ +# Skips spaces and equal signs (used by CNF parser) +skipspace: + # a0 - Input string + # Return: v0 - Address to first non-space character. + lbu $v1, 0($a0) + nop + beq $v1, ' ', .skip + nop + beq $v1, '=', .skip + nop + jr $ra + move $v0, $a0 +.skip: + b skipspace + addiu $a0, 1 + + +# Copies a string until a CR/LF or space is encountered +getline: + # a0 - Output address + # a1 - String to copy from + lbu $v0, 0($a1) + addiu $a1, 1 + beqz $v0, .end + nop + beq $v0, 0x0D, .end + nop + beq $v0, 0x0A, .end + nop + beq $v0, ' ', .end + nop + sb $v0, 0($a0) + b getline + addiu $a0, 1 +.end: + jr $ra + sb $0, 0($a0) + + +# strcasestr implementation +strcasestr: + # a0 - String to search + # a1 - String to find + addiu $sp, -24 + sw $ra, 0($sp) + sw $s0, 4($sp) + sw $s1, 8($sp) + sw $a1, 16($sp) + +.scan_start: + + sw $a0, 12($sp) + +.comp_loop: + + lbu $s0, 0($a0) # Load character from A and B + lbu $s1, 0($a1) + + beqz $s0, .end_strcasestr + nop + beqz $s1, .found + nop + + sw $a0, 20($sp) # Save a0 parameter + + jal toupper # tolower character A + move $a0, $s0 + move $s0, $v0 + + jal toupper # tolower character B + move $a0, $s1 + move $s1, $v0 + + lw $a0, 20($sp) # Restore a0 parameter + + addiu $a1, 1 + addiu $a0, 1 + + beq $s0, $s1, .comp_loop # If value matches continue compare + nop + +.end_strcasestr: + + lw $a0, 12($sp) # Rescan from next character of string A + lw $a1, 16($sp) + addiu $a0, 1 + + lbu $v0, 0($a0) + nop + beqz $v0, .not_found # If terminator is reached, string is not found + nop + + b .scan_start + nop + +.not_found: + + b .quit + move $v0, $0 + +.found: + + lw $v0, 12($sp) # Return address of string match + +.quit: + + lw $ra, 0($sp) + lw $s0, 4($sp) + lw $s1, 8($sp) + jr $ra + addiu $sp, 24 + + diff --git a/examples/lowlevel/cartrom/readme.txt b/examples/lowlevel/cartrom/readme.txt new file mode 100644 index 0000000..8d11a7f --- /dev/null +++ b/examples/lowlevel/cartrom/readme.txt @@ -0,0 +1,74 @@ +LibPSn00b Example Programs +Part of the PSn00bSDK Poject + +TurboBoot Example by Lameguy64 + + +Explanation: + +This example demonstrates how to create a ROM program to be used on a cheat +cartridge such as an Action Replay or Xplorer using GNU assembler. The program +stored in ROM is executed pretty much instantly on power-on. + +The PS1 BIOS can execute code from a ROM chip connected to the expansion port +(or Parallel I/O port) such as a cheat cartridge provided the valid headers +are present. However, the boot vectors are somewhat limited as it only +provides a preboot vector and a postboot vector. + +The preboot vector is executed at the earliest point of the BIOS start-up +sequence which means the RAM is almost completely blank and you can't execute +PS-EXEs from this point whearas the postboot vector is only executed between +the PS logo and game execution. To get around this limitation, the preboot +vector is used to execute code that places a breakpoint to a desired point +in memory and returns execution to the BIOS. This will effectively intercept +execution once it reaches the breakpoint allowing to run code from ROM with +an initialized kernel allowing for bootstrapping PS-EXEs from ROM, CD or +from a comms interface such as serial. + +The Xplorer and later Pro Action Replay cheat devices use this so called +'midboot' trick in their firmwares. + +In this TurboBoot example, the ROM program attempts to boot a PS-EXE from +CD using BIOS CD-ROM and file functions. It will also parse through the +SYSTEM.CNF to retrieve the file name of executable as well as some boot +parameters such as stack addres and number of TCBs and EvCBs. The ROM +program can fallback to attempting to load a PS-EXE named PSX.EXE if the +SYSTEM.CNF file does not exist like in the official BIOS. + +This example can also be used as a turbo boot utility as it boots straight +to the game, skipping the start-up animation altogether. It cannot be used +as a way to bypass the authentication check of an unmodified console however +(though it would help with bypassing the license data check on older Japanese +consoles) as the CD-ROM would only read data discs correctly IF the elusive +wobble groove containing the SCE string of the disc is present or when a +modchip is installed. It is possible to circumvent this by issuing special +'CD Unlock' commands (see nocash's psx-spx document) to the CD-ROM controller +which would effectively turn this into a chipless modchip solution that plugs +to the expansion port. However, the unlock commands only works on US and EU +consoles. + +It is possible and pretty trivial to boot a PS-EXE straight from ROM by +simply copying the program text from ROM to its desired location in RAM and +transferring execution to it. Such an example may be created in the future. + +This ROM program example had to be written entirely in assembly as C cannot +be used to write a ROM program even though it should be possible with some +assembly code to take care of the bootstrapping. GNU ld would complain about +'relocation truncation of R_MIPS_GPREL16' when you map program text to ROM +starting at 0x1f000000 (EXP ROM segment) and program data and bss sections +to RAM. Unknown how to get around this as all methods I've tried so far +either don't work or it just produces a massive binary file. + + +Building: + +To build this example, simply run make and a file named cartrom.rom should +be created. Run the ROM in no$psx (make sure a ISO image has been opened +first) or burn it to an Xplorer/PAR EEPROM (I recommend modding a PAR with +a DIP32 socket if you wish to program the chip externally which in many +cases would be easier). + + +Changelog: + +May 23, 2019 - Initial version. diff --git a/examples/lowlevel/cartrom/rom.ld b/examples/lowlevel/cartrom/rom.ld new file mode 100644 index 0000000..f3f9cd3 --- /dev/null +++ b/examples/lowlevel/cartrom/rom.ld @@ -0,0 +1,11 @@ +MEMORY { + ROM : ORIGIN = 0x1f000000, LENGTH = 256K +} + +ENTRY (entry) + +SECTIONS { + .text :{ + *(.text) + } >ROM +} diff --git a/examples/lowlevel/cartrom/rom.s b/examples/lowlevel/cartrom/rom.s new file mode 100644 index 0000000..14c1167 --- /dev/null +++ b/examples/lowlevel/cartrom/rom.s @@ -0,0 +1,399 @@ +# LibPSn00b Example Programs +# Part of the PSn00bSDk project +# +# TurboBoot Example by Lameguy64 +# + + +# Uncomment either PAR or XPLORER depending on the cartridge +# you're going to use (makes disabling turbo boot via switch to work) + +#.set PAR, 0 +#.set XPLORER, 1 + + +.set noreorder + +.include "cop0.inc" # Contains definitions for cop0 registers + +.set SP_base, 0x801ffff0 +.set BREAK_ADDR, 0xa0000040 # cop0 breakpoint vector address + + +.set RAM_buff, 2048 +.set RAM_handle, 2052 +.set RAM_tcb, 2056 +.set RAM_evcb, 2060 +.set RAM_stack, 2064 +.set RAM_psexe, 2068 + + +.set EXE_pc0, 0 # PS-EXE header offsets +.set EXE_gp0, 4 +.set EXE_taddr, 8 +.set EXE_tsize, 12 +.set EXE_daddr, 16 +.set EXE_dsize, 20 +.set EXE_baddr, 24 +.set EXE_bsize, 28 +.set EXE_spaddr, 32 +.set EXE_sp_size, 36 +.set EXE_sp, 40 +.set EXE_fp, 44 +.set EXE_gp, 48 +.set EXE_ret, 52 +.set EXE_base, 56 +.set EXE_datapos, 60 + + +.section .text + + +# ROM header +# +# The Licensed by... strings are essential otherwise the BIOS will not +# execute the boot vectors. Always make sure the tty message fields (string +# after Licensed by) must be no more than 80 bytes long and must have a null +# terminating byte. +# +# Postboot vector isn't particularly practical as its only executed in between +# the PS boot logo and the point where game execution occurs. +# +header: + # Postboot vector + .word 0 + .ascii "Licensed by Sony Computer Entertainment Inc." + .ascii "Not officially licensed or endorsed by Sony Computer Entertainment Inc." + + .balign 0x80 # This keeps things in the header aligned + + # Preboot vector + .word preboot + .ascii "Licensed by Sony Computer Entertainment Inc." + .ascii "Cart ROM example for PSn00bSDK https://github.com/lameguy64/psn00bsdk" + + .balign 0x80 # This keeps things in the header aligned + + +# Preboot vector +# +# All it does is it initializes a breakpoint vector at 0x40 +# and sets a cop0 breakpoint at 0x80030000 to perform a midboot +# exploit as preboot doesn't have the kernel area initialized. +# +preboot: + + li $v0, 1 + +.ifdef XPLORER + lui $a0, 0x1f06 # Read switch status for Xplorer + lbu $v0, 0($a0) +.endif + +.ifdef PAR + lui $a0, 0x1f02 # Read switch status for PAR/GS devices + lbu $v0, 0x18($a0) +.endif + + nop + andi $v0, 0x1 + beqz $v0, .no_rom # If switch is off don't install hook + nop # and effectively disables the cartridge + + li $v0, BREAK_ADDR # Patch a jump at cop0 breakpoint vector + + li $a0, 0x3c1a1f00 # lui $k0, $1f00 + sw $a0, 0($v0) + la $a1, entry # ori $k0, < address to code entrypoint > + andi $a1, 0xffff + lui $a0, 0x375a + or $a0, $a1 + sw $a0, 4($v0) + li $a0, 0x03400008 # jr $k0 + sw $a0, 8($v0) + sw $0 , 12($v0) # nop + + lui $v0, 0xffff # Set BPCM and BDAM masks + ori $v0, 0xffff + mtc0 $v0, BDAM + mtc0 $v0, BPCM + + + li $v0, 0x80030000 # Set break on PC and data-write address + + mtc0 $v0, BDA # BPC break is for compatibility with no$psx + mtc0 $v0, BPC # as it does not emulate break on BDA + + lui $v0, 0xeb80 # Enable break on data-write and and break + mtc0 $v0, DCIC # on PC to DCIC control register + +.no_rom: + + jr $ra # Return to BIOS + nop + + +# Actual ROM entrypoint +.global entry +entry: + + mtc0 $0 , DCIC # Clear DCIC register + + la $sp, SP_base # Set stack base + la $gp, 0x8000c000 # Set GP address as RAM base addr in this case + + jal SetDefaultExitFromException # Set default exit handler just in case + nop + jal ExitCriticalSection # Exit out of critical section (brings back interrupts) + nop + + # Beyond this point, the PS1 is in full control to the ROM + + la $a0, m_banner # Print out program banner + jal printf + addiu $sp, -4 + addiu $sp, 4 + + la $a0, m_cdinit + jal printf + addiu $sp, -4 + addiu $sp, 4 + + jal _96_init # Initialize the CD + nop + + la $a0, m_ok # Print OK message if init didn't crash + jal printf + addiu $sp, -4 + addiu $sp, 4 + + la $a0, m_readfile + la $a1, s_systemcnf + jal printf + addiu $sp, -8 + addiu $sp, 8 + + la $a0, s_systemcnf # Attempt to open the SYSTEM.CNF file on CD + li $a1, 1 + jal open + addiu $sp, -8 + addiu $sp, 8 + + bltz $v0, .no_systemcnf # Fallback to loading PSX.EXE if not found + nop + + sw $v0, RAM_handle($gp) # Save file handle + + move $a0, $v0 # Read file contents of SYSTEM.CNF + move $a1, $gp + li $a2, 0x0800 + jal read + addiu $sp, -12 + addiu $sp, 12 + + lw $a0, RAM_handle($gp) # Close file + jal close + addiu $sp, -4 + addiu $sp, 4 + + la $a0, m_ok # Output ok message + jal printf + addiu $sp, -4 + addiu $sp, 4 + + # Parse CNF file + + la $a0, m_parsecnf + jal printf + nop + + la $a1, s_tcb # Get TCB number + jal strcasestr + move $a0, $gp + jal skipspace # Skip spaces + addiu $a0, $v0, 3 + addiu $a0, $v0, -2 # Step two charactters back and inject '0x' + li $v0, '0' + sb $v0, 0($a0) + li $v0, 'x' + sb $v0, 1($a0) + jal atoi + addiu $sp, -4 + addiu $sp, 4 + move $s1, $v0 + + la $a1, s_evcb # Get EVCB number + jal strcasestr + move $a0, $gp + jal skipspace + addiu $a0, $v0, 5 + addiu $a0, $v0, -2 + li $v0, '0' + sb $v0, 0($a0) + li $v0, 'x' + sb $v0, 1($a0) + jal atoi + addiu $sp, -4 + addiu $sp, 4 + move $s0, $v0 + + la $a1, s_stack # Get STACK address + jal strcasestr + move $a0, $gp + jal skipspace + addiu $a0, $v0, 5 + addiu $a0, $v0, -2 + li $v0, '0' + sb $v0, 0($a0) + li $v0, 'x' + sb $v0, 1($a0) + jal atoi + addiu $sp, -4 + addiu $sp, 4 + move $s2, $v0 + + la $a1, s_boot # Get the PS-EXE file name + jal strcasestr + move $a0, $gp + + jal skipspace # Skip spaces + addiu $a0, $v0, 4 + + addiu $a0, $gp, RAM_psexe # Extract the line + jal getline + move $a1, $v0 + + la $a0, m_ok # Print successful parsing + jal printf + addiu $sp, -4 + addiu $sp, 4 + + la $a0, m_readfile + addiu $a1, $gp, RAM_psexe + jal printf + addiu $sp, -8 + addiu $sp, 8 + + b .do_load # Proceed loading PS-EXE + addiu $a0, $gp, RAM_psexe + +.no_systemcnf: # Load fallback + + la $a0, m_notfound + jal printf + addiu $sp, -4 + addiu $sp, 4 + + la $a0, m_fallback + jal printf + addiu $sp, -4 + addiu $sp, 4 + + li $s0, 0x10 # Default EvCBs and TCBs + li $s1, 0x04 + li $s2, SP_base # Default stack + la $a0, s_psxexe # Attempt loading PSX.EXE + +.do_load: + + jal LoadExe # Load PS-EXE + move $a1, $gp + + beqz $v0, load_fail + nop + + la $a0, m_ok + jal printf + addiu $sp, -4 + addiu $sp, 4 + + sw $s2, EXE_sp($gp) # Patch the header + sw $s2, EXE_spaddr($gp) + + la $a0, m_boot + jal printf + addiu $sp, -4 + addiu $sp, 4 + + jal EnterCriticalSection # Disable interrupt handling + nop + + move $a0, $s0 # Set configuration (EvCBs and TCBs) + move $a1, $s1 + move $a2, $s2 + jal SetConf + addiu $sp, -12 + addiu $sp, 12 + + move $a0, $gp # Transfer execution + move $a1, $0 + move $a2, $0 + jal DoExec + addiu $sp, -12 + addiu $sp, 12 + + +load_fail: # Fail state + la $a0, m_loadfail + jal printf + nop +.fail_loop: + b .fail_loop + nop + + +.include "parse.inc" +.include "bios.inc" + + +# Strings + +s_boot: + .asciz "BOOT" + .balign 4 +s_tcb: + .asciz "TCB" + .balign 4 +s_evcb: + .asciz "EVENT" + .balign 4 +s_stack: + .asciz "STACK" + .balign 4 +s_systemcnf: + .asciz "cdrom:SYSTEM.CNF;1" + .balign 4 +s_psxexe: + .asciz "cdrom:PSX.EXE;1" + .balign 4 + + +# Message strings + +m_banner: + .asciz "\nCARTROM Bootstrap Example by Lameguy64\nPart of the PSn00bSDK Project\n\n" + .balign 4 +m_cdinit: + .asciz "Initializing CD-ROM (BIOS)... " + .balign 4 +m_readfile: + .asciz "Attempting to read %s... " + .balign 4 +m_parsecnf: + .asciz "Parsing CNF file... " + .balign 4 +m_fallback: + .asciz "Falling back to loading PSX.EXE... " + .balign 4 +m_notfound: + .asciiz "Not found.\n" + .balign 4 +m_ok: + .asciz "Ok.\n" + .balign 4 +m_boot: + .asciz "Boot!\n" + .balign 4 +m_loadfail: + .asciz "Failed to load PS-EXE file.\n" + .balign 4 diff --git a/examples/makefile b/examples/makefile index 4c4aadf..00911a6 100644 --- a/examples/makefile +++ b/examples/makefile @@ -1,11 +1,27 @@ # Run using make (Linux) or gmake (BSD) # Part of the PSn00bSDK Project -# 2019 Lameguy64 / Meido-Tek Productions +# 2019-2020 Lameguy64 / Meido-Tek Productions TOPTARGETS = all clean -DIRS = balls gte n00bdemo fpscam childexec render2tex rgb24 timer billboard +# Beginner examples +DIRS = beginner/hello +# Graphics examples +DIRS += graphics/balls graphics/billboard graphics/fpscam graphics/gte \ + graphics/render2tex graphics/rgb24 + +# System related examples +DIRS += system/childexec system/console system/timer + +# Low-level examples +DIRS += lowlevel/cartrom + +# CD-ROM examples +DIRS += cdrom/cdbrowse cdrom/cdxa + +# Demos +DIRS += demos/n00bdemo $(TOPTARGETS): $(DIRS) $(DIRS): diff --git a/examples/n00bdemo/data.h b/examples/n00bdemo/data.h deleted file mode 100644 index 3be0e3d..0000000 --- a/examples/n00bdemo/data.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _DATA_H -#define _DATA_H - -extern unsigned char lz_resources[]; - -/*extern unsigned char smd_mtekdisk[]; -extern unsigned char smd_mtektext[]; -extern unsigned char smd_star[]; -extern unsigned char smd_psn00b[]; -extern unsigned char smd_scarletlogo[];*/ - -#endif \ No newline at end of file diff --git a/examples/n00bdemo/data.s b/examples/n00bdemo/data.s deleted file mode 100644 index 3ca33cb..0000000 --- a/examples/n00bdemo/data.s +++ /dev/null @@ -1,31 +0,0 @@ -.section .data - -.global lz_resources -.type lz_resources, @object -lz_resources: - .incbin "data.lzp" - -#.global smd_mtekdisk -#.type smd_mtekdisk, @object -#smd_mtekdisk: -# .incbin "data/mtekdisk.smd" - -#.global smd_mtektext -#.type smd_mtektext, @object -#smd_mtektext: -# .incbin "data/mtektext.smd" - -#.global smd_star -#.type smd_star, @object -#smd_star: -# .incbin "data/star.smd" - -#.global smd_psn00b -#.type smd_psn00b, @object -#smd_psn00b: -# .incbin "data/psn00blogo.smd" - -#.global smd_scarletlogo -#.type smd_scarletlogo, @object -#smd_scarletlogo: -# .incbin "data/scarletlogo.smd" \ No newline at end of file diff --git a/examples/n00bdemo/data.xml b/examples/n00bdemo/data.xml deleted file mode 100644 index 292a325..0000000 --- a/examples/n00bdemo/data.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - data/petscum16c.tim - data/bungirl.tim - - - data/clktower.tim - data/riftbld1.tim - data/riftbld2.tim - data/hatkid.tim - - data/celmapi.tim - - data/lamelotl16c.tim - data/n00blogo-pixel.tim - data/font.tim - - - - - - - data/mtekdisk.smd - data/mtektext.smd - data/star.smd - data/psn00blogo.smd - data/logo.smd - - - data/petscum.smd - data/bulb.smd - - - data/bungirl.smd - - data/star_mask.smd - data/timerift.smd - data/rbowshade.smd - - data/hatkid.smd - - - textures.qlp - - - - \ No newline at end of file diff --git a/examples/n00bdemo/data/bulb.smd b/examples/n00bdemo/data/bulb.smd deleted file mode 100644 index 9b77c6d..0000000 Binary files a/examples/n00bdemo/data/bulb.smd and /dev/null differ diff --git a/examples/n00bdemo/data/bulb.smx b/examples/n00bdemo/data/bulb.smx deleted file mode 100644 index 89225e6..0000000 --- a/examples/n00bdemo/data/bulb.smx +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/n00bdemo/data/bungirl.smd b/examples/n00bdemo/data/bungirl.smd deleted file mode 100644 index 63f96b5..0000000 Binary files a/examples/n00bdemo/data/bungirl.smd and /dev/null differ diff --git a/examples/n00bdemo/data/bungirl.smx b/examples/n00bdemo/data/bungirl.smx deleted file mode 100644 index 6093d70..0000000 --- a/examples/n00bdemo/data/bungirl.smx +++ /dev/null @@ -1,5608 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/n00bdemo/data/bungirl.tim b/examples/n00bdemo/data/bungirl.tim deleted file mode 100644 index 11ee9f4..0000000 Binary files a/examples/n00bdemo/data/bungirl.tim and /dev/null differ diff --git a/examples/n00bdemo/data/celmapi.bmp b/examples/n00bdemo/data/celmapi.bmp deleted file mode 100644 index f44f94f..0000000 Binary files a/examples/n00bdemo/data/celmapi.bmp and /dev/null differ diff --git a/examples/n00bdemo/data/celmapi.tim b/examples/n00bdemo/data/celmapi.tim deleted file mode 100644 index c043e0b..0000000 Binary files a/examples/n00bdemo/data/celmapi.tim and /dev/null differ diff --git a/examples/n00bdemo/data/clktower.tim b/examples/n00bdemo/data/clktower.tim deleted file mode 100644 index 15c6edc..0000000 Binary files a/examples/n00bdemo/data/clktower.tim and /dev/null differ diff --git a/examples/n00bdemo/data/font.bmp b/examples/n00bdemo/data/font.bmp deleted file mode 100644 index 1d078f3..0000000 Binary files a/examples/n00bdemo/data/font.bmp and /dev/null differ diff --git a/examples/n00bdemo/data/font.tim b/examples/n00bdemo/data/font.tim deleted file mode 100644 index 64cdad2..0000000 Binary files a/examples/n00bdemo/data/font.tim and /dev/null differ diff --git a/examples/n00bdemo/data/hatkid.png b/examples/n00bdemo/data/hatkid.png deleted file mode 100644 index 369ce32..0000000 Binary files a/examples/n00bdemo/data/hatkid.png and /dev/null differ diff --git a/examples/n00bdemo/data/hatkid.smd b/examples/n00bdemo/data/hatkid.smd deleted file mode 100644 index a68f414..0000000 Binary files a/examples/n00bdemo/data/hatkid.smd and /dev/null differ diff --git a/examples/n00bdemo/data/hatkid.smx b/examples/n00bdemo/data/hatkid.smx deleted file mode 100644 index f9e8012..0000000 --- a/examples/n00bdemo/data/hatkid.smx +++ /dev/null @@ -1,1281 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/n00bdemo/data/hatkid.tim b/examples/n00bdemo/data/hatkid.tim deleted file mode 100644 index b2e9318..0000000 Binary files a/examples/n00bdemo/data/hatkid.tim and /dev/null differ diff --git a/examples/n00bdemo/data/lamelotl16c.png b/examples/n00bdemo/data/lamelotl16c.png deleted file mode 100644 index 67490c8..0000000 Binary files a/examples/n00bdemo/data/lamelotl16c.png and /dev/null differ diff --git a/examples/n00bdemo/data/lamelotl16c.tim b/examples/n00bdemo/data/lamelotl16c.tim deleted file mode 100644 index 194c034..0000000 Binary files a/examples/n00bdemo/data/lamelotl16c.tim and /dev/null differ diff --git a/examples/n00bdemo/data/lightworld.smd b/examples/n00bdemo/data/lightworld.smd deleted file mode 100644 index 4c1bb59..0000000 Binary files a/examples/n00bdemo/data/lightworld.smd and /dev/null differ diff --git a/examples/n00bdemo/data/lightworld.smx b/examples/n00bdemo/data/lightworld.smx deleted file mode 100644 index 665e8c9..0000000 --- a/examples/n00bdemo/data/lightworld.smx +++ /dev/null @@ -1,1097 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/n00bdemo/data/logo.smd b/examples/n00bdemo/data/logo.smd deleted file mode 100644 index 9eb1954..0000000 Binary files a/examples/n00bdemo/data/logo.smd and /dev/null differ diff --git a/examples/n00bdemo/data/logo.smx b/examples/n00bdemo/data/logo.smx deleted file mode 100644 index 1ed0549..0000000 --- a/examples/n00bdemo/data/logo.smx +++ /dev/null @@ -1,1169 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/n00bdemo/data/mtekdisk.smd b/examples/n00bdemo/data/mtekdisk.smd deleted file mode 100644 index f99bd46..0000000 Binary files a/examples/n00bdemo/data/mtekdisk.smd and /dev/null differ diff --git a/examples/n00bdemo/data/mtekdisk.smx b/examples/n00bdemo/data/mtekdisk.smx deleted file mode 100644 index fce2fa2..0000000 --- a/examples/n00bdemo/data/mtekdisk.smx +++ /dev/null @@ -1,379 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/n00bdemo/data/mtektext.smd b/examples/n00bdemo/data/mtektext.smd deleted file mode 100644 index a158521..0000000 Binary files a/examples/n00bdemo/data/mtektext.smd and /dev/null differ diff --git a/examples/n00bdemo/data/mtektext.smx b/examples/n00bdemo/data/mtektext.smx deleted file mode 100644 index 50aa59d..0000000 --- a/examples/n00bdemo/data/mtektext.smx +++ /dev/null @@ -1,671 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/n00bdemo/data/n00blogo-pixel.png b/examples/n00bdemo/data/n00blogo-pixel.png deleted file mode 100644 index db7aa89..0000000 Binary files a/examples/n00bdemo/data/n00blogo-pixel.png and /dev/null differ diff --git a/examples/n00bdemo/data/n00blogo-pixel.tim b/examples/n00bdemo/data/n00blogo-pixel.tim deleted file mode 100644 index c372593..0000000 Binary files a/examples/n00bdemo/data/n00blogo-pixel.tim and /dev/null differ diff --git a/examples/n00bdemo/data/petscum.smd b/examples/n00bdemo/data/petscum.smd deleted file mode 100644 index 9a1c8eb..0000000 Binary files a/examples/n00bdemo/data/petscum.smd and /dev/null differ diff --git a/examples/n00bdemo/data/petscum.smx b/examples/n00bdemo/data/petscum.smx deleted file mode 100644 index 8f1b9e5..0000000 --- a/examples/n00bdemo/data/petscum.smx +++ /dev/null @@ -1,1093 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/n00bdemo/data/petscum16c.png b/examples/n00bdemo/data/petscum16c.png deleted file mode 100644 index c9d115c..0000000 Binary files a/examples/n00bdemo/data/petscum16c.png and /dev/null differ diff --git a/examples/n00bdemo/data/petscum16c.tim b/examples/n00bdemo/data/petscum16c.tim deleted file mode 100644 index 18af842..0000000 Binary files a/examples/n00bdemo/data/petscum16c.tim and /dev/null differ diff --git a/examples/n00bdemo/data/psn00blogo.smd b/examples/n00bdemo/data/psn00blogo.smd deleted file mode 100644 index 3c1412a..0000000 Binary files a/examples/n00bdemo/data/psn00blogo.smd and /dev/null differ diff --git a/examples/n00bdemo/data/psn00blogo.smx b/examples/n00bdemo/data/psn00blogo.smx deleted file mode 100644 index 0921b6c..0000000 --- a/examples/n00bdemo/data/psn00blogo.smx +++ /dev/null @@ -1,745 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/n00bdemo/data/rbowshade.smd b/examples/n00bdemo/data/rbowshade.smd deleted file mode 100644 index c218d05..0000000 Binary files a/examples/n00bdemo/data/rbowshade.smd and /dev/null differ diff --git a/examples/n00bdemo/data/rbowshade.smx b/examples/n00bdemo/data/rbowshade.smx deleted file mode 100644 index 6648b5d..0000000 --- a/examples/n00bdemo/data/rbowshade.smx +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/n00bdemo/data/riftbld1.tim b/examples/n00bdemo/data/riftbld1.tim deleted file mode 100644 index 5581bb3..0000000 Binary files a/examples/n00bdemo/data/riftbld1.tim and /dev/null differ diff --git a/examples/n00bdemo/data/riftbld2.tim b/examples/n00bdemo/data/riftbld2.tim deleted file mode 100644 index 4048024..0000000 Binary files a/examples/n00bdemo/data/riftbld2.tim and /dev/null differ diff --git a/examples/n00bdemo/data/star.smd b/examples/n00bdemo/data/star.smd deleted file mode 100644 index 68a5725..0000000 Binary files a/examples/n00bdemo/data/star.smd and /dev/null differ diff --git a/examples/n00bdemo/data/star.smx b/examples/n00bdemo/data/star.smx deleted file mode 100644 index c91947e..0000000 --- a/examples/n00bdemo/data/star.smx +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/n00bdemo/data/star_mask.smd b/examples/n00bdemo/data/star_mask.smd deleted file mode 100644 index fe624fe..0000000 Binary files a/examples/n00bdemo/data/star_mask.smd and /dev/null differ diff --git a/examples/n00bdemo/data/star_mask.smx b/examples/n00bdemo/data/star_mask.smx deleted file mode 100644 index 695bd47..0000000 --- a/examples/n00bdemo/data/star_mask.smx +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/n00bdemo/data/timerift.smd b/examples/n00bdemo/data/timerift.smd deleted file mode 100644 index dc22e4d..0000000 Binary files a/examples/n00bdemo/data/timerift.smd and /dev/null differ diff --git a/examples/n00bdemo/data/timerift.smx b/examples/n00bdemo/data/timerift.smx deleted file mode 100644 index 38d53f6..0000000 --- a/examples/n00bdemo/data/timerift.smx +++ /dev/null @@ -1,1085 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/n00bdemo/disp.c b/examples/n00bdemo/disp.c deleted file mode 100644 index d798ee9..0000000 --- a/examples/n00bdemo/disp.c +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include -#include -#include "smd.h" -#include "disp.h" - -DISPENV disp; -DRAWENV draw; - -char pribuff[2][131072]; -unsigned int ot[2][OT_LEN]; -char *nextpri; -int db = 0; - -MATRIX mtx; - - -void initDisplay() { - - ResetGraph( 3 ); - - if( GetVideoMode() == MODE_NTSC ) { - SetDefDispEnv( &disp, 0, 0, 640, 480 ); - SetDefDrawEnv( &draw, 0, 0, 640, 480 ); - scSetClipRect( 0, 0, 640, 480 ); - printf("NTSC System.\n"); - } else { - SetDefDispEnv( &disp, 0, 0, 640, 512 ); - SetDefDrawEnv( &draw, 0, 0, 640, 512 ); - scSetClipRect( 0, 0, 640, 512 ); - disp.screen.y = 20; - disp.screen.h = 256; - printf("PAL System.\n"); - } - - disp.isinter = 1; - draw.isbg = 1; - - PutDispEnv( &disp ); - PutDrawEnv( &draw ); - - ClearOTagR( ot[0], OT_LEN ); - ClearOTagR( ot[1], OT_LEN ); - nextpri = pribuff[0]; - - InitGeom(); - gte_SetGeomScreen( 320 ); - - if( GetVideoMode() == MODE_NTSC ) { - gte_SetGeomOffset( 320, 240 ); - } else { - gte_SetGeomOffset( 320, 256 ); - } - -} - -void display() { - - DrawSync(0); - VSync(0); - - PutDrawEnv( &draw ); - DrawOTag( ot[db]+OT_LEN-1 ); - - db ^= 1; - ClearOTagR( ot[db], OT_LEN ); - nextpri = pribuff[db]; - - SetDispMask( 1 ); - -} \ No newline at end of file diff --git a/examples/n00bdemo/disp.h b/examples/n00bdemo/disp.h deleted file mode 100644 index ecf6dcf..0000000 --- a/examples/n00bdemo/disp.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _DISP_H -#define _DISP_H - -#include - -#define SCENE_TIME 60*15 - -#define CENTERX 320 -#define CENTERY 240 - -#define OT_LEN 260 - -void initDisplay(); -void display(); - -extern unsigned int ot[2][OT_LEN]; -extern char *nextpri; -extern int db; - -extern DISPENV disp; -extern DRAWENV draw; - -extern MATRIX mtx; - -#endif // _DISP_H \ No newline at end of file diff --git a/examples/n00bdemo/lightdemo.c b/examples/n00bdemo/lightdemo.c deleted file mode 100644 index ff858c0..0000000 --- a/examples/n00bdemo/lightdemo.c +++ /dev/null @@ -1,494 +0,0 @@ -#include -#include -#include -#include -#include "disp.h" -#include "smd.h" - -extern MATRIX lgt_colmtx; - -extern SMD *o_world; -extern SMD *o_lightbulb; - -void sort_overlay(int showlotl); - -void lightdemo() { - - /* - The point lighting demo is perhaps the most impressive part of - n00bDEMO. A more streamlined version of this demo where you control - various attributes of the light source such as position, intensity - and color might be made as a dedicated example program in the future. - - The point lighting trick is actually not that too complicated. You - basically calculate the distance and direction vector of two points - which are the light source and the vertex of a polygon. - - Calculating the normal whose result can later be used to calculate - the distance between two points is achieved with: - - vec_dir.vx = lgt_point.vx - pri_vert.vx; - vec_dir.vy = lgt_point.vy - pri_vert.vy; - vec_dir.vz = lgt_point.vz - pri_vert.vz; - - The intensity is calculated with (this might not be accurate but this - is faster than applying a square root): - - i = 4096 - ( ( - (vec_dir.vx*vec_dir.vx) + - (vec_dir.vy*vec_dir.vy) + - (vec_dir.vz*vec_dir.vz) ) >> 7 ); - - // Clip minimum intensity - if( i < 0 ) - i = 0; - - This intensity value is then used to set the color of the light source - through the light color matrix. - - col_mtx.m[0][0] = i; - col_mtx.m[1][0] = i; - col_mtx.m[2][0] = i; - gte_SetColorMatrix( &col_mtx ); - - The direction vector can then be used as the direction of the light - source. It is recommended to normalize it first to prevent possible - overflow related issues. - - VectorNormalS( &vec_dir, &vec_norm ); - - lgt_mtx.m[0][0] = vec_norm.vx; - lgt_mtx.m[0][1] = vec_norm.vy; - lgt_mtx.m[0][2] = vec_norm.vz; - - gte_SetLightMatrix( &lgt_mtx ); - - This operation is then performed for each point of a polygon to - achieve a nice smooth shaded point lighting effect. The macros used - are still the same as doing light source calculation with the GTE - the normal way. - - 3D geometry still requires normal data as with most lighting - processing operations. 'Flat' normals (faces with a single normal - vector) work best on flat surfaces while 'smooth' normals (faces with - normals on each point) work best on round or curved surfaces. - - */ - - int i,p_ang; - - SC_OT s_ot; - - SVECTOR rot; - VECTOR pos; - SMD_PRIM s_pri; - - VECTOR l_point; - SVECTOR nrm; - - MATRIX lmtx,llmtx,omtx; - - SVECTOR orot = { 0 }; - - int timeout = SCENE_TIME; - - - // Set clear color to black - setRGB0( &draw, 0, 0, 0 ); - - // Base values for the environment geometry - setVector( &pos, 0, 0, 600 ); - setVector( &rot, 512, 0, 0 ); - - // Set base tpage value for the SMD drawing routines - smdSetBaseTPage( 0x200 ); - - // Set back or ambient color to black for pure darkness - gte_SetBackColor( 0, 0, 0 ); - - memset( &llmtx, 0, sizeof(MATRIX) ); - - - // demo loop - while( 1 ) { - - char buff[32]; - - RotMatrix( &rot, &mtx ); - TransMatrix( &mtx, &pos ); - - rot.vy += 4; - - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - - setVector( &l_point, (icos( p_ang )>>2)>>2, -350+(icos( p_ang<<1 )>>4), (isin( p_ang )>>2)>>2 ); - p_ang += 16; - - - // Begin parsing the SMD data of the environment - OpenSMD( o_world ); - - // Prototype point lighting renderer - while( ReadSMD( &s_pri ) ) { - - VECTOR v_dir; - SVECTOR v_nrm; - VECTOR v_sqr; - - int flg; - - if( s_pri.prim_id.texture ) { - - POLY_GT4 *pri; - - // Perform standard rotate, translate and perspective - // transformation of the geometry - pri = (POLY_GT4*)nextpri; - - gte_ldv3( - &o_world->p_verts[s_pri.v0], - &o_world->p_verts[s_pri.v1], - &o_world->p_verts[s_pri.v2] ); - - gte_rtpt(); - - gte_nclip(); // Backface culling - - gte_stopz( &flg ); - - if( flg < 0 ) - continue; - - gte_stsxy3( &pri->x0, &pri->x1, &pri->x2 ); - - gte_ldv0( &o_world->p_verts[s_pri.v3] ); - gte_rtps(); - - gte_avsz4(); // Depth sort - gte_stotz( &flg ); - - if( (flg>>2) >= OT_LEN ) - continue; - - gte_stsxy( &pri->x3 ); - - - // Load base color of polygon to GTE - gte_ldrgb( &s_pri.r0 ); - - // Load normal of polygon - gte_ldv0( &o_world->p_norms[s_pri.n0] ); - - // Calculate the direction between the vertex of the - // polygon and the light source - v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v0].vx; - v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v0].vy; - v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v0].vz; - - // Calculate distance and light intensity using square - i = 4096 - ( ( - (v_dir.vx*v_dir.vx) + - (v_dir.vy*v_dir.vy) + - (v_dir.vz*v_dir.vz) ) >> 7 ); - - // Clip minimum intensity - if( i < 0 ) - i = 0; - - // Set intensity to color matrix - llmtx.m[0][0] = i; - llmtx.m[1][0] = i; - llmtx.m[2][0] = i; - gte_SetColorMatrix( &llmtx ); - - // Normalize light direction and set it to light matrix - VectorNormalS( &v_dir, &v_nrm ); - lmtx.m[0][0] = v_nrm.vx; - lmtx.m[0][1] = v_nrm.vy; - lmtx.m[0][2] = v_nrm.vz; - gte_SetLightMatrix( &lmtx ); - - // Calculate (output is retrieved through gte_strgb) - gte_nccs(); - - - // Repeat process for the next 3 vertices - v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v1].vx; - v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v1].vy; - v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v1].vz; - - i = 4096 - ( ( - (v_dir.vx*v_dir.vx) + - (v_dir.vy*v_dir.vy) + - (v_dir.vz*v_dir.vz) ) >> 7 ); - - if( i < 0 ) - i = 0; - - - llmtx.m[0][0] = i; - llmtx.m[1][0] = i; - llmtx.m[2][0] = i; - - gte_strgb( &pri->r0 ); - - gte_SetColorMatrix( &llmtx ); - VectorNormalS( &v_dir, &v_nrm ); - lmtx.m[0][0] = v_nrm.vx; - lmtx.m[0][1] = v_nrm.vy; - lmtx.m[0][2] = v_nrm.vz; - gte_SetLightMatrix( &lmtx ); - gte_nccs(); - - v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v2].vx; - v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v2].vy; - v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v2].vz; - - i = 4096 - ( ( - (v_dir.vx*v_dir.vx) + - (v_dir.vy*v_dir.vy) + - (v_dir.vz*v_dir.vz) ) >> 7 ); - - if( i < 0 ) - i = 0; - - llmtx.m[0][0] = i; - llmtx.m[1][0] = i; - llmtx.m[2][0] = i; - - gte_strgb( &pri->r1 ); - - gte_SetColorMatrix( &llmtx ); - VectorNormalS( &v_dir, &v_nrm ); - lmtx.m[0][0] = v_nrm.vx; - lmtx.m[0][1] = v_nrm.vy; - lmtx.m[0][2] = v_nrm.vz; - gte_SetLightMatrix( &lmtx ); - gte_nccs(); - - v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v3].vx; - v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v3].vy; - v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v3].vz; - - i = 4096 - ( ( - (v_dir.vx*v_dir.vx) + - (v_dir.vy*v_dir.vy) + - (v_dir.vz*v_dir.vz) ) >> 7 ); - - if( i < 0 ) - i = 0; - - llmtx.m[0][0] = i; - llmtx.m[1][0] = i; - llmtx.m[2][0] = i; - - gte_strgb( &pri->r2 ); - - gte_SetColorMatrix( &llmtx ); - VectorNormalS( &v_dir, &v_nrm ); - lmtx.m[0][0] = v_nrm.vx; - lmtx.m[0][1] = v_nrm.vy; - lmtx.m[0][2] = v_nrm.vz; - gte_SetLightMatrix( &lmtx ); - gte_nccs(); - - setUV4( pri, - s_pri.tu0, s_pri.tv0, - s_pri.tu1, s_pri.tv1, - s_pri.tu2, s_pri.tv2, - s_pri.tu3, s_pri.tv3 ); - - pri->tpage = s_pri.tpage; - pri->clut = s_pri.clut; - - setPolyGT4( pri ); - addPrim( ot[db]+(flg>>2), pri ); - nextpri += sizeof(POLY_GT4); - - gte_strgb( &pri->r3 ); - - } else { - - POLY_G4 *pri; - - pri = (POLY_G4*)nextpri; - - gte_ldv3( - &o_world->p_verts[s_pri.v0], - &o_world->p_verts[s_pri.v1], - &o_world->p_verts[s_pri.v2] ); - - gte_rtpt(); - - gte_nclip(); - - gte_stopz( &flg ); - - if( flg < 0 ) - continue; - - gte_stsxy3( &pri->x0, &pri->x1, &pri->x2 ); - - gte_ldv0( &o_world->p_verts[s_pri.v3] ); - gte_rtps(); - - gte_avsz4(); - gte_stotz( &flg ); - - if( (flg>>2) >= OT_LEN ) - continue; - - gte_stsxy( &pri->x3 ); - - gte_ldrgb( &s_pri.r0 ); - gte_ldv0( &o_world->p_norms[s_pri.n0] ); - - v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v0].vx; - v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v0].vy; - v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v0].vz; - - i = 4096 - ( ( - (v_dir.vx*v_dir.vx) + - (v_dir.vy*v_dir.vy) + - (v_dir.vz*v_dir.vz) ) >> 7 ); - - if( i < 0 ) - i = 0; - - llmtx.m[0][0] = i; - llmtx.m[1][0] = i; - llmtx.m[2][0] = i; - gte_SetColorMatrix( &llmtx ); - VectorNormalS( &v_dir, &v_nrm ); - lmtx.m[0][0] = v_nrm.vx; - lmtx.m[0][1] = v_nrm.vy; - lmtx.m[0][2] = v_nrm.vz; - gte_SetLightMatrix( &lmtx ); - gte_nccs(); - - - v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v1].vx; - v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v1].vy; - v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v1].vz; - - i = 4096 - ( ( - (v_dir.vx*v_dir.vx) + - (v_dir.vy*v_dir.vy) + - (v_dir.vz*v_dir.vz) ) >> 7 ); - - if( i < 0 ) - i = 0; - - llmtx.m[0][0] = i; - llmtx.m[1][0] = i; - llmtx.m[2][0] = i; - - gte_strgb( &pri->r0 ); - - gte_SetColorMatrix( &llmtx ); - VectorNormalS( &v_dir, &v_nrm ); - lmtx.m[0][0] = v_nrm.vx; - lmtx.m[0][1] = v_nrm.vy; - lmtx.m[0][2] = v_nrm.vz; - gte_SetLightMatrix( &lmtx ); - gte_nccs(); - - v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v2].vx; - v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v2].vy; - v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v2].vz; - - i = 4096 - ( ( - (v_dir.vx*v_dir.vx) + - (v_dir.vy*v_dir.vy) + - (v_dir.vz*v_dir.vz) ) >> 7 ); - - if( i < 0 ) - i = 0; - - llmtx.m[0][0] = i; - llmtx.m[1][0] = i; - llmtx.m[2][0] = i; - - gte_strgb( &pri->r1 ); - - gte_SetColorMatrix( &llmtx ); - VectorNormalS( &v_dir, &v_nrm ); - lmtx.m[0][0] = v_nrm.vx; - lmtx.m[0][1] = v_nrm.vy; - lmtx.m[0][2] = v_nrm.vz; - gte_SetLightMatrix( &lmtx ); - gte_nccs(); - - v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v3].vx; - v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v3].vy; - v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v3].vz; - - i = 4096 - ( ( - (v_dir.vx*v_dir.vx) + - (v_dir.vy*v_dir.vy) + - (v_dir.vz*v_dir.vz) ) >> 7 ); - - if( i < 0 ) - i = 0; - - llmtx.m[0][0] = i; - llmtx.m[1][0] = i; - llmtx.m[2][0] = i; - - gte_strgb( &pri->r2 ); - - gte_SetColorMatrix( &llmtx ); - VectorNormalS( &v_dir, &v_nrm ); - lmtx.m[0][0] = v_nrm.vx; - lmtx.m[0][1] = v_nrm.vy; - lmtx.m[0][2] = v_nrm.vz; - gte_SetLightMatrix( &lmtx ); - gte_nccs(); - - setPolyG4( pri ); - addPrim( ot[db]+(flg>>2), pri ); - - nextpri += sizeof(POLY_G4); - - gte_strgb( &pri->r3 ); - - } - - } - - - // Sort the light bulb to represent the position of the light source - orot.vx += 32; - orot.vy += 32; - orot.vz += 32; - - RotMatrix( &orot, &omtx ); - TransMatrix( &omtx, &l_point ); - - CompMatrixLV( &mtx, &omtx, &mtx ); - - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - s_ot.ot = ot[db]; - s_ot.otlen = OT_LEN; - s_ot.zdiv = 2; - s_ot.zoff = 0; - - nextpri = smdSortModel( &s_ot, nextpri, o_lightbulb ); - - - // Sort overlay and display - sort_overlay( 1 ); - - display(); - - timeout--; - if( timeout < 0 ) - break; - - } - -} \ No newline at end of file diff --git a/examples/n00bdemo/logo.c b/examples/n00bdemo/logo.c deleted file mode 100644 index 3fdef5e..0000000 --- a/examples/n00bdemo/logo.c +++ /dev/null @@ -1,428 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "malloc.h" -#include "smd.h" -#include "lzp.h" - -#include "disp.h" -#include "data.h" - -#define MAX_STARS 64 - - -typedef struct { - int x,y; - int xvel,yvel; - int scale; - int rot,rotv; -} PARTICLE; - -typedef struct { - unsigned int tag; - unsigned int tpage; - unsigned int mask1; - unsigned char r0,g0,b0,code; - short x0,y0; - short x1,y1; - short x2,y2; - short x3,y3; - unsigned int mask2; -} MASKP_F4; - -typedef struct { - unsigned int tag; - unsigned int tpage; - unsigned char r0,g0,b0,code; - short x0,y0; - short w,h; -} FADERECT; - - -SMD *o_psn00b, *o_n00blogo; - - -typedef struct { - unsigned int *prev; - unsigned int *next; - int size; -} NODE; - -void DumpHeap() { - - NODE *n = (NODE*)GetBSSend(); - - printf( "--\n" ); - - while( 1 ) { - - printf( "B:%08p P:%08p N:%08p SZ:%d BS:%d\n", - n, n->prev, n->next, n->size, - ((unsigned int)n->next - (unsigned int)n) ); - - if ( !n->next ) - break; - - n = (NODE*)n->next; - - } - -} - - -void intro() { - - SVECTOR quad_coords[] = { - { -100, -100, 0, 0 }, - { 100, -100, 0, 0 }, - { -100, 100, 0, 0 }, - { 100, 100, 0, 0 } - }; - - PARTICLE stars[MAX_STARS]; - - VECTOR mpos; - SVECTOR mrot,trot; - SC_OT s_ot; - - SMD *o_disk, *o_star, *o_text, *o_psn00b, *o_n00blogo; - - int i,count = 0; - - int logo_scale; - int logo_rot; - - int logo_yvel; - int logo_ypos; - int logo_step; - int logo_spin; - int logo_svel; - int logo_count = 0; - int logo_tscale; - - int logo_n00b_spin; - int logo_fade = 0; - - struct { - int step; - int yvel; - int ypos; - int rot; - int scale; - int spin; - int spinvel; - int tscale; - int trot; - } mtek = { - 0, - 0, - ONE*750, - -ONE*512, - ONE*7, - 0, - 0, - 3072, - 0 - }; - - struct { - VECTOR pos; - int scale; - int scarlet_spin; - } psn00b = { - { 0, 0, 0 }, - ONE, - 1024 - }; - - - i = lzpSearchFile( "mtekdisk", lz_resources ); - o_disk = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); - lzpUnpackFile( o_disk, lz_resources, i ); - smdInitData( o_disk ); - - i = lzpSearchFile( "mtektext", lz_resources ); - o_text = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); - lzpUnpackFile( o_text, lz_resources, i ); - smdInitData( o_text ); - - i = lzpSearchFile( "starsprite", lz_resources ); - o_star = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); - lzpUnpackFile( o_star, lz_resources, i ); - smdInitData( o_star ); - - i = lzpSearchFile( "psn00blogo", lz_resources ); - o_psn00b = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); - lzpUnpackFile( o_psn00b, lz_resources, i ); - smdInitData( o_psn00b ); - - i = lzpSearchFile( "n00blogo", lz_resources ); - o_n00blogo = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); - lzpUnpackFile( o_n00blogo, lz_resources, i ); - smdInitData( o_n00blogo ); - - //DumpHeap(); - - - // Set some Scarlet global parameters - smdSetBaseTPage( 0x200 ); - - // Change clear color - setRGB0( &draw, 255, 255, 255 ); - - setVector( &trot, 0, 0, 0 ); - - - // Initialize stars - for( i=0; i 360 ) { - mtek.spin -= mtek.spinvel; - mtek.spinvel += 1280; - } - - setVector( &mpos, 0, -(mtek.ypos>>12)-20, 400 ); - setVector( &mrot, 0, mtek.spin>>12, mtek.rot>>12 ); - - RotMatrix( &mrot, &mtx ); - TransMatrix( &mtx, &mpos ); - setVector( &mpos, mtek.scale, mtek.scale, 4096 ); - ScaleMatrix( &mtx, &mpos ); - - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - nextpri = smdSortModelFlat( ot[db]+10, nextpri, o_disk ); - - - if( mtek.step > 0 ) { - - setVector( &mpos, 0, 180, 400 ); - TransMatrix( &mtx, &mpos ); - gte_SetTransMatrix( &mtx ); - - nextpri = smdSortModelFlat( ot[db]+8, nextpri, o_text ); - - if( logo_count < 480 ) { - - SVECTOR srot; - - for( i=0; i>12, stars[i].y>>12, 320 ); - setVector( &srot, 0, 0, stars[i].rot>>12 ); - - stars[i].x += stars[i].xvel; - stars[i].y += stars[i].yvel; - - stars[i].yvel += 512; - stars[i].rot += stars[i].rotv; - - RotMatrix( &srot, &mtx ); - TransMatrix( &mtx, &mpos ); - - setVector( &mpos, stars[i].scale, stars[i].scale, 4096 ); - ScaleMatrix( &mtx, &mpos ); - - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - nextpri = smdSortModelFlat( ot[db]+6, nextpri, o_star ); - - } - - } - - } - - if( !mtek.step ) { - mtek.rot -= ONE*20; - } else if( mtek.step == 1 ) { - mtek.rot += ( -mtek.rot )>>4; - } - - - if( mtek.step < 2 ) { - mtek.scale += (ONE-mtek.scale )>>5; - mtek.yvel += 512; - mtek.ypos -= mtek.yvel; - } - - - if( ( mtek.ypos <= 0 ) && ( mtek.yvel > 0 ) ) { - mtek.yvel = -ONE*6; - mtek.step++; - } - - // Does the transition effect - if( logo_count > 480 ) { - - TILE *rect = (TILE*)nextpri; - - mtek.trot += 16; - - setTile( rect ); - setXY0( rect, 0, 0 ); - setWH( rect, 640, 511 ); - setRGB0( rect, 0, 0, 0 ); - addPrim( ot[db]+4, rect ); - nextpri += sizeof(TILE); - - setVector( &mrot, 0, 0, mtek.trot ); - setVector( &mpos, mtek.tscale, mtek.tscale, 4096 ); - - RotMatrix( &mrot, &mtx ); - ScaleMatrix( &mtx, &mpos ); - - gte_SetRotMatrix( &mtx ); - - for( i=0; i<6; i++ ) { - - MASKP_F4 *pol4 = (MASKP_F4*)nextpri; - - setVector( &mpos, -100+(100*(i%3)), -60+(120*(i/3)), 160 ); - TransMatrix( &mtx, &mpos ); - gte_SetTransMatrix( &mtx ); - - pol4->tag = 0x08000000; - pol4->tpage = 0xe1000020; - pol4->mask1 = 0xe6000001; - pol4->mask2 = 0xe6000002; - pol4->code = 0x2A; - - gte_ldv3( &quad_coords[0], &quad_coords[1], &quad_coords[2] ); - gte_rtpt(); - gte_stsxy0( &pol4->x0 ); - gte_ldv0( &quad_coords[3] ); - gte_rtps(); - gte_stsxy3( &pol4->x1, &pol4->x2, &pol4->x3 ); - setRGB0( pol4, 0, 0, 0 ); - - addPrim( ot[db]+4, pol4 ); - nextpri += sizeof(MASKP_F4); - - } - - mtek.tscale += ( -mtek.tscale )>>6; - - } - - } else { - - setRGB0( &draw, 0, 0, 0 ); - - } - - if( logo_count >= 480 ) { - - if( logo_count > 840 ) { - - psn00b.pos.vx += ((ONE*-450)-psn00b.pos.vx)>>4; - psn00b.pos.vy += ((ONE*350)-psn00b.pos.vy)>>4; - - setVector( &mpos, 0, 0, 600 ); - mpos.vx = psn00b.pos.vx>>12; - mpos.vy = psn00b.pos.vy>>12; - - psn00b.scale += ( 1536-psn00b.scale )>>4; - - setVector( &mrot, 0, 0, 0 ); - - RotMatrix( &mrot, &mtx ); - TransMatrix( &mtx, &mpos ); - - setVector( &mpos, psn00b.scale, psn00b.scale, ONE ); - - ScaleMatrix( &mtx, &mpos ); - - } else { - - setVector( &mpos, 0, 0, 600 ); - setVector( &mrot, 0, logo_n00b_spin, 0 ); - - RotMatrix( &mrot, &mtx ); - TransMatrix( &mtx, &mpos ); - - logo_n00b_spin += ( -logo_n00b_spin )>>6; - - } - - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - nextpri = smdSortModelFlat( ot[db]+3, nextpri, o_psn00b ); - - if( logo_count > 900 ) { - - setVector( &mpos, 0, 0, 250 ); - setVector( &mrot, psn00b.scarlet_spin, 0, 0 ); - - RotMatrix( &mrot, &mtx ); - TransMatrix( &mtx, &mpos ); - - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - nextpri = smdSortModelFlat( ot[db]+3, nextpri, o_n00blogo ); - - psn00b.scarlet_spin += ( -psn00b.scarlet_spin )>>6; - - } - - } - - if( logo_count > 1200 ) { - - FADERECT *fade = (FADERECT*)nextpri; - - fade->tag = 0x04000000; - fade->tpage = 0xe1000040; - fade->code = 0x62; - - setRGB0( fade, logo_fade, logo_fade, logo_fade ); - setXY0( fade, 0, 0 ); - setWH( fade, 640, 480 ); - addPrim( ot[db]+2, fade ); - - if( logo_fade < 250 ) { - logo_fade += 4; - } - - nextpri += sizeof(FADERECT); - - } - - display(); - - logo_count++; - - } - - free( o_disk ); - free( o_text ); - free( o_star ); - free( o_psn00b ); - free( o_n00blogo ); - -} diff --git a/examples/n00bdemo/logo.h b/examples/n00bdemo/logo.h deleted file mode 100644 index 6429c8e..0000000 --- a/examples/n00bdemo/logo.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _LOGO_H -#define _LOGO_H - -void intro(); - -#endif // _LOGO_H diff --git a/examples/n00bdemo/main.c b/examples/n00bdemo/main.c deleted file mode 100644 index a6eb57e..0000000 --- a/examples/n00bdemo/main.c +++ /dev/null @@ -1,650 +0,0 @@ -/* - * LibPSn00b Example Programs - * - * n00bDEMO Source Code - * 2019 Meido-Tek Productions / PSn00bSDK Project - * - * To build, simply run make. Make sure you have the lzpack tool accessible - * through your PATH environment variable. - * - * Demo by Lameguy64 - * - * Changelog: - * - * Apr 4, 2019 - Some code clean-up and added more comments. - * - * Mar 20, 2019 - Initial completed version. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "malloc.h" -#include "smd.h" -#include "data.h" -#include "disp.h" -#include "logo.h" -#include "plasma_tbl.h" - - -// Standard light color matrix -MATRIX lgt_colmtx = { - //#1,#2,#3 - ONE, 0, 0, // R - ONE, 0, 0, // G - ONE, 0, 0 // B -}; - -// SMD data global pointers -SMD *o_rbowshade; -SMD *o_world, *o_lightbulb; -SMD *o_timerift, *o_star; -SMD *o_hatkid,*o_bungirl;; - -// TPage and CLUT globals -unsigned short lamelotl_tpage,psn00b_tpage; -unsigned short font_tpage,font_clut; -SPRT llotl_sprite; -SPRT psn00b_sprite; - - -// Some function definition -void sort_overlay(int showlotl); -void lightdemo(); - - -void UploadTIM(TIM_IMAGE *tim) { - - /* - Very simple texture upload function - */ - - LoadImage( tim->prect, tim->paddr ); - - if( tim->mode & 0x8 ) - LoadImage( tim->crect, tim->caddr ); - -} - -void loadTextures() { - - /* - Unpack textures from an embedded LZP archive and upload them to VRAM. - */ - int i; - int *tex_buff,*ttim,j; - TIM_IMAGE tim; - - i = lzpSearchFile( "textures", lz_resources ); - tex_buff = (int*)malloc( lzpFileSize( lz_resources, i ) ); - lzpUnpackFile( tex_buff, lz_resources, i ); - - - for( j=0; jx, tim.prect->y )|0x200; - setSprt( &psn00b_sprite ); - setClut( &psn00b_sprite, tim.crect->x, tim.crect->y ); - setWH( &psn00b_sprite, tim.prect->w<<2, tim.prect->h ); - setUV0( &psn00b_sprite, (tim.prect->x%64)<<2, tim.prect->y ); - setRGB0( &psn00b_sprite, 128, 128, 128 ); - - - GetTimInfo( (unsigned int*)qlpFileAddr( - qlpFindFile( "lamelotl", tex_buff ), tex_buff ), &tim ); - - UploadTIM( &tim ); - - lamelotl_tpage = getTPage( 0, 0, tim.prect->x, tim.prect->y )|0x200; - setSprt( &llotl_sprite ); - setClut( &llotl_sprite, tim.crect->x, tim.crect->y ); - setWH( &llotl_sprite, tim.prect->w<<2, tim.prect->h ); - setUV0( &llotl_sprite, 0, 0 ); - setRGB0( &llotl_sprite, 128, 128, 128 ); - - - GetTimInfo( (unsigned int*)qlpFileAddr( - qlpFindFile( "celmap", tex_buff ), tex_buff ), &tim ); - - UploadTIM( &tim ); - - smdSetCelTex( getTPage( 0, 2, tim.prect->x, tim.prect->y )|0x200, - getClut( tim.crect->x, tim.crect->y ) ); - smdSetCelParam( 3, 3, 0x4f4f4f ); - - - GetTimInfo( (unsigned int*)qlpFileAddr( - qlpFindFile( "font", tex_buff ), tex_buff ), &tim ); - - UploadTIM( &tim ); - - font_tpage = getTPage( 0, 1, tim.prect->x, tim.prect->y )|0x200; - font_clut = getClut( tim.crect->x, tim.crect->y ); - -} - -void unpackModels() { - - /* - Unpack model data from an embedded LZP archive. - */ - - int i; - - i = lzpSearchFile( "rbowshade", lz_resources ); - o_rbowshade = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); - lzpUnpackFile( o_rbowshade, lz_resources, i ); - smdInitData( o_rbowshade ); - - i = lzpSearchFile( "bungirl", lz_resources ); - o_bungirl = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); - lzpUnpackFile( o_bungirl, lz_resources, i ); - smdInitData( o_bungirl ); - - i = lzpSearchFile( "lightworld", lz_resources ); - o_world = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); - lzpUnpackFile( o_world, lz_resources, i ); - smdInitData( o_world ); - - i = lzpSearchFile( "lightbulb", lz_resources ); - o_lightbulb = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); - lzpUnpackFile( o_lightbulb, lz_resources, i ); - smdInitData( o_lightbulb ); - - i = lzpSearchFile( "timerift", lz_resources ); - o_timerift = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); - lzpUnpackFile( o_timerift, lz_resources, i ); - smdInitData( o_timerift ); - - i = lzpSearchFile( "starmask", lz_resources ); - o_star = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); - lzpUnpackFile( o_star, lz_resources, i ); - smdInitData( o_star ); - - i = lzpSearchFile( "hatkid", lz_resources ); - o_hatkid = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); - lzpUnpackFile( o_hatkid, lz_resources, i ); - smdInitData( o_hatkid ); - -} - -void init() { - - int i; - - // Init display - initDisplay(); - - FntLoad( 960, 0 ); - - // Just to remove all sound - SpuInit(); - - // Load all textures - loadTextures(); - -} - -// Bungirl stuff -void bungirldemo() { - - /* - The bunny girl demo is just a simple demonstration of rendering a 1390 - polygon 3D model of a bunny girl with lighting using SMD drawing routines - from Scarlet Engine. - */ - - SC_OT s_ot; - - MATRIX lmtx; - - SVECTOR rot,brot,srot; - VECTOR pos; - - int timeout = SCENE_TIME; - - // Set clear color - setRGB0( &draw, 63, 0, 127 ); - - // Set tpage base value for SMD drawing routines - smdSetBaseTPage( 0x200 ); - - // Set initial rotation values - setVector( &rot, 192, 0, 0 ); - setVector( &brot, 0, 0, 128 ); - setVector( &srot, 0, 0, 0 ); - - // Set lighting color matrix - gte_SetColorMatrix( &lgt_colmtx ); - - // Set 'backside' or ambient light color - gte_SetBackColor( 113, 113, 113 ); - - - // Demo loop - while( 1 ) { - - // Bungirl position - setVector( &pos, 0, 50, 350 ); - - TransMatrix( &mtx, &pos ); - RotMatrix( &brot, &mtx ); - - // Calculate light matrix - lmtx.m[0][0] = isin( -brot.vy<<2 ); - lmtx.m[0][1] = -2048; - lmtx.m[0][2] = icos( -brot.vy<<2 ); - - MulMatrix0( &lmtx, &mtx, &lmtx ); - - // Set matrices - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - gte_SetLightMatrix( &lmtx ); - - // Sort the bungirl model - s_ot.ot = ot[db]; - s_ot.otlen = OT_LEN; - s_ot.zdiv = 1; - s_ot.zoff = 0; - nextpri = smdSortModel( &s_ot, nextpri, o_bungirl ); - - - // Sort the rotating rainbow background - setVector( &pos, 0, 0, 200 ); - - TransMatrix( &mtx, &pos ); - RotMatrix( &srot, &mtx ); - - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - nextpri = smdSortModelFlat( ot[db]+(OT_LEN-1), nextpri, o_rbowshade ); - - brot.vy += 8; - srot.vz += 4; - - - // Sort overlay then display - sort_overlay( 0 ); - - display(); - - timeout--; - if( timeout < 0 ) - break; - - } - -} - -// Stencil effect stuff -void stencilstuff() { - - /* - The stencil demo is achieved by utilizing the mask bit setting - primitive GP0(E6h). The structure of this primitive is defined as - DR_MASK initialized and set by setDrawMask(). These are not available - in Sony's SDK by default. - - The DR_MASK primitive controls mask bit operations for drawing - primitives such as setting mask bits on every pixel drawn or mask - bit test where pixels won't be drawn on pixels with the mask bit set. - It applies to most graphics drawing primitives except VRAM fill. - The mask bits are stored in the 16th bit of each pixel drawn. - - The semi-transparency bits of a texture always carry over as mask - bits in textured primitives. The only way to clear mask bits is by - using VRAM fill commands or drawing primitives with the set mask - bit operation disabled. - - The stencil effect featured in this demo is achieved by enabling set - mask bit with DR_MASK, drawing semi-transparent primitives using - additive blending but color is all zero to make it completely invisible - but is enough to update the mask bits, disable mask set bit but enable - mask test with DR_MASK and then drawing a rectangle that fills the - entire screen. Semi-transparency mask in textures must not be used when - drawing the scene that will be 'below' the mask layer. - */ - int timeout = SCENE_TIME; - - int spin=0; - - DR_MASK *mask; - TILE *rect; - - SC_OT s_ot; - - SVECTOR rot; - SVECTOR srot; - VECTOR pos; - - // Set clear color - setRGB0( &draw, 127, 0, 63 ); - - // Set tpage base value for SMD drawing routines - smdSetBaseTPage( 0x200 ); - - // Base rotation coordinates - setVector( &rot, 0, 0, 0 ); - setVector( &srot, 0, 0, 0 ); - - // Set perspective - gte_SetGeomScreen( 320 ); - - - // Demo loop - while( timeout > 0 ) { - - - // Draw the timerift background - setVector( &rot, 0, spin, 0 ); - setVector( &pos, 0, 0, 0 ); - - TransMatrix( &mtx, &pos ); - RotMatrix( &rot, &mtx ); - - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - s_ot.ot = ot[db]; - s_ot.otlen = 32; - s_ot.zdiv = 2; - s_ot.zoff = 20; - - nextpri = smdSortModelFlat( ot[db]+(OT_LEN-1), nextpri, o_timerift ); - - - // Sort mask primitive that enables setting mask bits - mask = (DR_MASK*)nextpri; - setDrawMask( mask, 1, 0 ); - addPrim( ot[db]+20, mask ); - nextpri += sizeof(DR_MASK); - - - // Sort the stars - setVector( &rot, 0, 0, spin<<2 ); - setVector( &pos, - (isin(spin<<2)*icos(spin))>>16, - (icos(spin<<2)*isin(spin))>>16, 400 ); - - TransMatrix( &mtx, &pos ); - RotMatrix( &rot, &mtx ); - - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - nextpri = smdSortModelFlat( ot[db]+19, nextpri, o_star ); - - setVector( &rot, 0, 0, -spin<<2 ); - setVector( &pos, - (isin(-spin<<2)*icos(-spin))>>16, - (icos(-spin<<2)*isin(-spin))>>16, 400 ); - - TransMatrix( &mtx, &pos ); - RotMatrix( &rot, &mtx ); - - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - nextpri = smdSortModelFlat( ot[db]+19, nextpri, o_star ); - - - // Sort mask primitive that enables mask bit test - mask = (DR_MASK*)nextpri; - setDrawMask( mask, 0, 1 ); - addPrim( ot[db]+18, mask ); - nextpri += sizeof(DR_MASK); - - - // Sort rectangle that fills the screen - rect = (TILE*)nextpri; - setTile( rect ); - setXY0( rect, 0, 0 ); - setWH( rect, 640, 511 ); - setRGB0( rect, 128, 0, 255 ); - addPrim( ot[db]+17, rect ); - nextpri += sizeof(TILE); - - - // Clear all mask settings - mask = (DR_MASK*)nextpri; - setDrawMask( mask, 0, 0 ); - addPrim( ot[db]+15, mask ); - nextpri += sizeof(DR_MASK); - - - // Sort overlay then display - sort_overlay( 0 ); - - display(); - - spin += 4; - timeout--; - } - -} - -// Orbiting around cel-shaded hatkid stuff -void hatkidstuff() { - - /* - The cel-shading effect works in a similar manner as conventional - per-vertex light source calculation except the color values are used - in a different manner. The resulting color values are divided down - using bit shifts to fit as texture coordinates (usually within the - range of 0-31) which are then used to map to a shading map which is a - simple texture of 3 to 4 shading levels. This technique is very similar - to how cel-shading is achieved on the Gamecube except all the vertex to - texture coordinate conversion is all done on the GX itself. - - To achieve this effect on untextured and textured polygons seamlessly - the shading map is drawn over the original unshaded polygons of the - model as semi-transparent polygons with subtractive blending. The - shading map had to be inverted for this effect to work properly since - blending is subtractive and not multiplicative after all. - */ - - int timeout = SCENE_TIME; - int spin=0; - - SC_OT s_ot; - - MATRIX lmtx; - - SVECTOR rot; - VECTOR pos; - - // Set clear color - setRGB0( &draw, 127, 0, 63 ); - - // Sets base TPage value for SMD drawing routines - smdSetBaseTPage( 0x200 ); - - setVector( &rot, 0, 0, 0 ); - - // Set light color matrix - gte_SetColorMatrix( &lgt_colmtx ); - - // Set back/ambient color to black (required for good cel-shading) - gte_SetBackColor( 0, 0, 0 ); - - gte_SetGeomScreen( 320 ); - - // Demo loop - while( timeout > 0 ) { - - // Sort 3D timerift background - setVector( &rot, spin, spin, spin>>1 ); - setVector( &pos, 0, 0, 0 ); - - TransMatrix( &mtx, &pos ); - RotMatrix( &rot, &mtx ); - - // Fixed light source direction - lmtx.m[0][0] = -2048; - lmtx.m[0][1] = -2048; - lmtx.m[0][2] = -2048; - - // Multiply by rotation matrix to make it relative to the camera rotation - MulMatrix0( &lmtx, &mtx, &lmtx ); - - gte_SetLightMatrix( &lmtx ); - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - nextpri = smdSortModelFlat( ot[db]+(OT_LEN-1), nextpri, o_timerift ); - - - // Sort the cel-shaded hatkid - setVector( &pos, 0, 0, 600 ); - TransMatrix( &mtx, &pos ); - gte_SetTransMatrix( &mtx ); - - s_ot.ot = ot[db]; - s_ot.otlen = 250; - s_ot.zdiv = 1; - s_ot.zoff = 0; - - nextpri = smdSortModelCel( &s_ot, nextpri, o_hatkid ); - - - // Sort overlay then display - sort_overlay( 1 ); - display(); - - spin += 8; - timeout--; - - } - -} - -// Plasma stuff -void genPlasma(char *out, int count); -char *sortPlasma(int *ot, char *pri, char *map); - -void plasmastuff() { - - DR_TPAGE* tp; - char plasbuff[1271]; - - int pcount = 0; - int timeout = SCENE_TIME; - - while( timeout > 0 ) { - - genPlasma( plasbuff, pcount ); - nextpri = sortPlasma( ot[db]+1, nextpri, plasbuff ); - - sort_overlay( 1 ); - - display(); - timeout--; - pcount++; - - } - -} - -// Simple stripe transition effect -void transition() { - - int i,count,comp; - int bheight[16] = { 0 }; - - TILE *tile = (TILE*)nextpri; - draw.isbg = 0; - - while( 1 ) { - - comp = 0; - - for( i=0; i<16; i++ ) { - - if( bheight[i] > 0 ) { - - - setTile( tile ); - setXY0( tile, 0, 32*i ); - setRGB0( tile, 0, 151, 255 ); - setWH( tile, 640, bheight[i] ); - addPrim( ot[db], tile ); - tile++; - - if( bheight[i] < 32 ) - bheight[i]++; - else - comp++; - - } - - } - - if( bheight[count>>1] == 0 ) - bheight[count>>1] = 1; - - display(); - count++; - - if( comp >= 16 ) - break; - - } - - DrawSync(0); - - draw.isbg = 1; - -} - -int main(int argc, const char *argv[]) { - - // Init - init(); - - // Do transition - transition(); - - // Do Meido-Tek, PSn00bSDK and n00bDEMO logo intros - intro(); - - // Unpack model data - unpackModels(); - - // Demo sequence loop - while( 1 ) { - - lightdemo(); - bungirldemo(); - stencilstuff(); - hatkidstuff(); - plasmastuff(); - - } - - return 0; -} \ No newline at end of file diff --git a/examples/n00bdemo/makefile b/examples/n00bdemo/makefile deleted file mode 100644 index 96275fb..0000000 --- a/examples/n00bdemo/makefile +++ /dev/null @@ -1,45 +0,0 @@ -include ../sdk-common.mk - -TARGET = demo.elf - -CFILES = $(notdir $(wildcard *.c)) -AFILES = $(notdir $(wildcard *.s)) - -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) - -INCLUDE += -I../../libpsn00b/lzp -LIBDIRS += -L../../libpsn00b/lzp - -LIBS = -llzp -lc -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc - -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x - -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -AS = $(PREFIX)as -LD = $(PREFIX)ld - -all: resources $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -resources: - lzpack data.xml - touch data.s - -iso: - mkpsxiso -y -q -o demo.iso iso.xml - -clean: - rm -rf build *.lzp *.qlp $(TARGET) $(TARGET:.elf=.exe) $(TARGET:.elf=.iso) diff --git a/examples/n00bdemo/overlay.c b/examples/n00bdemo/overlay.c deleted file mode 100644 index 847bc96..0000000 --- a/examples/n00bdemo/overlay.c +++ /dev/null @@ -1,199 +0,0 @@ -#include -#include -#include -#include "disp.h" - -extern const char scroll_text[]; -extern unsigned short lamelotl_tpage,psn00b_tpage; -extern unsigned short font_tpage,font_clut; - -extern SPRT llotl_sprite; -extern SPRT psn00b_sprite; - -u_char font_width[] = { - 10 ,6 ,12 ,16 ,12 ,14 ,14 ,8 ,10 ,10 ,14 ,12 ,8 ,14 ,6 ,14 , - 14 ,6 ,12 ,13 ,14 ,14 ,14 ,14 ,14 ,14 ,6 ,8 ,12 ,14 ,12 ,14 , - 14 ,14 ,14 ,13 ,14 ,14 ,14 ,14 ,14 ,14 ,14 ,14 ,12 ,15 ,14 ,14 , - 14 ,14 ,14 ,13 ,14 ,15 ,15 ,16 ,16 ,16 ,16 ,10 ,14 ,10 ,14 ,14 , - 8 ,14 ,13 ,11 ,13 ,12 ,13 ,12 ,13 ,6 ,14 ,14 ,8 ,16 ,14 ,14 , - 14 ,14 ,13 ,12 ,12 ,14 ,14 ,14 ,13 ,13 ,14 ,10 ,6 ,10 ,16 ,16 -}; - -int scrolltext_pos = 640; -int scrolltext_cpos = 0; -int overlay_count = 0; - -void sort_overlay(int showlotl) { - - SPRT *spr; - SPRT_16 *spr16; - DR_TPAGE *tp; - POLY_G4 *quad; - LINE_G2 *line; - - int i = scrolltext_cpos; - int j, k, tx, par_end = 0; - - tx = scrolltext_pos; - - while( scroll_text[i] != 0 ) { - - if( scroll_text[i] == '\n' ) { - par_end = 1; - break; - } - - j = scroll_text[i]-32; - - if( j > 0 ) { - - spr16 = (SPRT_16*)nextpri; - setSprt16( spr16 ); - setSemiTrans( spr16, 1 ); - setXY0( spr16, tx, 28 ); - setUV0( spr16, (j%16)<<4, (j>>4)<<4 ); - - if( tx < 128 ) { - k = tx; - if( k < 0 ) - k = 0; - setRGB0( spr16, k, k, k ); - } else if( tx > 512 ) { - k = 128-(tx-512); - if( k < 0 ) - k = 0; - setRGB0( spr16, k, k, k ); - } else { - setRGB0( spr16, 128, 128, 128 ); - } - - spr16->clut = font_clut; - addPrim( ot[db], spr16 ); - nextpri += sizeof(SPRT_16); - - } - - tx += font_width[j]; - - if( tx > 640 ) - break; - - i++; - - } - - scrolltext_pos -= 4; - j = scroll_text[scrolltext_cpos]-32; - if( j >= 0 ) { - - if( scrolltext_pos <= -font_width[j] ) { - - scrolltext_pos += font_width[j]; - scrolltext_cpos++; - - } - - } else { - - scrolltext_pos = 0; - scrolltext_cpos++; - - if( par_end ) - scrolltext_pos = 640; - - if( scroll_text[scrolltext_cpos] == 0 ) { - scrolltext_cpos = 0; - scrolltext_pos = 640; - } - - } - - line = (LINE_G2*)nextpri; - setLineG2( line ); - setSemiTrans( line, 1 ); - setXY2( line, 0, 46, 320, 46 ); - setRGB0( line, 0, 0, 0 ); - setRGB1( line, 255, 255, 255 ); - addPrim( ot[db], line ); - line++; - setLineG2( line ); - setSemiTrans( line, 1 ); - setXY2( line, 320, 46, 640, 46 ); - setRGB0( line, 255, 255, 255 ); - setRGB1( line, 0, 0, 0 ); - addPrim( ot[db], line ); - line++; - nextpri = (char*)line; - - tp = (DR_TPAGE*)nextpri; - setDrawTPage( tp, 0, 1, font_tpage ); - addPrim( ot[db], tp ); - nextpri += sizeof(DR_TPAGE); - - quad = (POLY_G4*)nextpri; - setPolyG4( quad ); - setSemiTrans( quad, 1 ); - setXY4( quad, - 0, 25, 320, 25, - 0, 46, 320, 46 ); - setRGB0( quad, 0, 0, 0 ); - setRGB1( quad, 64, 64, 64 ); - setRGB2( quad, 0, 0, 0 ); - setRGB3( quad, 64, 64, 64 ); - addPrim( ot[db], quad ); - quad++; - setPolyG4( quad ); - setSemiTrans( quad, 1 ); - setXY4( quad, - 320, 25, 640, 25, - 320, 46, 640, 46 ); - setRGB0( quad, 64, 64, 64 ); - setRGB1( quad, 0, 0, 0 ); - setRGB2( quad, 64, 64, 64 ); - setRGB3( quad, 0, 0, 0 ); - addPrim( ot[db], quad ); - quad++; - nextpri = (char*)quad; - - i = isin( overlay_count )>>9; - - if( GetVideoMode() == MODE_PAL ) { - j = 32; - } else { - j = 0; - } - - tp = (DR_TPAGE*)nextpri; - setDrawTPage( tp, 0, 1, getTPage( 0, 2, 0, 0 ) ); - addPrim( ot[db], tp ); - nextpri += sizeof(DR_TPAGE); - - if( showlotl ) { - - spr = (SPRT*)nextpri; - *spr = llotl_sprite; - setXY0( spr, 440, (200+j)+i ); - addPrim( ot[db], spr ); - nextpri += sizeof(SPRT); - - tp = (DR_TPAGE*)nextpri; - setDrawTPage( tp, 0, 1, lamelotl_tpage ); - addPrim( ot[db], tp ); - nextpri += sizeof(DR_TPAGE); - - } - - spr = (SPRT*)nextpri; - *spr = psn00b_sprite; - setXY0( spr, 8, (400+j)-i ); - addPrim( ot[db], spr ); - nextpri += sizeof(SPRT); - - tp = (DR_TPAGE*)nextpri; - setDrawTPage( tp, 0, 1, psn00b_tpage ); - addPrim( ot[db], tp ); - nextpri += sizeof(DR_TPAGE); - - overlay_count += 32; - -} \ No newline at end of file diff --git a/examples/n00bdemo/plasma_tbl.c b/examples/n00bdemo/plasma_tbl.c deleted file mode 100644 index af6654a..0000000 --- a/examples/n00bdemo/plasma_tbl.c +++ /dev/null @@ -1,500 +0,0 @@ -// These are from Meido-Demo which was a very simple demo I made back in 2013 -// Man, time sure does fly. - Lameguy64 - -unsigned int plasma_colors[256] = { - 0x00000000, - 0x00000408, - 0x00040811, - 0x0008111a, - 0x00081623, - 0x000d1f2c, - 0x00112335, - 0x0011273d, - 0x0016304a, - 0x001a3553, - 0x001f3d5b, - 0x001f4163, - 0x00234a6b, - 0x00274e73, - 0x0027537b, - 0x002c5b83, - 0x00305f8e, - 0x00356795, - 0x00356b9c, - 0x00396fa3, - 0x003d77aa, - 0x003d7bb1, - 0x004183b7, - 0x004687bd, - 0x00468ac6, - 0x004a92cb, - 0x004e95d0, - 0x00539cd5, - 0x0053a0da, - 0x0057a7df, - 0x005baae3, - 0x005bade7, - 0x005fb4ec, - 0x0063b7ef, - 0x0067bdf2, - 0x0067c0f5, - 0x006bc6f7, - 0x006fc8f9, - 0x006fcbfb, - 0x0073d0fc, - 0x0077d3fe, - 0x007bd8fe, - 0x007bdafe, - 0x007fdcfe, - 0x0083e1fe, - 0x0083e3fe, - 0x0087e7fd, - 0x008ae8fb, - 0x008eecf9, - 0x008eeef7, - 0x0092eff5, - 0x0095f2f2, - 0x0095f3ef, - 0x0099f6ec, - 0x009cf7e8, - 0x009cf8e5, - 0x00a0fadf, - 0x00a3fbda, - 0x00a7fcd5, - 0x00a7fdd0, - 0x00aafdcb, - 0x00adfec6, - 0x00adfec0, - 0x00b1feba, - 0x00b4ffb1, - 0x00b7feaa, - 0x00b7fea3, - 0x00bafe9c, - 0x00bdfd95, - 0x00bdfd8e, - 0x00c0fb87, - 0x00c3fb7f, - 0x00c3fa73, - 0x00c6f86b, - 0x00c8f763, - 0x00cbf55b, - 0x00cbf353, - 0x00cef14a, - 0x00d0ef41, - 0x00d0ee39, - 0x00d3ea2c, - 0x00d5e823, - 0x00d8e51a, - 0x00d8e311, - 0x00dae108, - 0x00dcdc00, - 0x00dcda08, - 0x00dfd511, - 0x00e1d31f, - 0x00e3ce27, - 0x00e3cb30, - 0x00e5c839, - 0x00e7c341, - 0x00e7c04a, - 0x00e8ba53, - 0x00eab75b, - 0x00eab467, - 0x00ecad6f, - 0x00eeaa77, - 0x00efa37f, - 0x00efa087, - 0x00f1998e, - 0x00f29595, - 0x00f2929c, - 0x00f38aa7, - 0x00f587ad, - 0x00f67fb4, - 0x00f67bba, - 0x00f773c0, - 0x00f86fc6, - 0x00f86bcb, - 0x00f963d0, - 0x00fa5fd8, - 0x00fb57dc, - 0x00fb53e1, - 0x00fb4ee5, - 0x00fc46e8, - 0x00fc41ec, - 0x00fd39ef, - 0x00fd35f2, - 0x00fe2cf6, - 0x00fe27f8, - 0x00fe23fa, - 0x00fe1afb, - 0x00fe16fd, - 0x00fe0dfe, - 0x00fe08fe, - 0x00fe04fe, - 0x00fe04fe, - 0x00fe08fe, - 0x00fe11fd, - 0x00fe16fc, - 0x00fe1ffb, - 0x00fe23f9, - 0x00fe27f7, - 0x00fe30f5, - 0x00fd35f1, - 0x00fd3dee, - 0x00fd41ea, - 0x00fc46e7, - 0x00fb4ee3, - 0x00fb53df, - 0x00fb5bda, - 0x00fa5fd5, - 0x00f967ce, - 0x00f96bc8, - 0x00f86fc3, - 0x00f777bd, - 0x00f77bb7, - 0x00f683b1, - 0x00f587aa, - 0x00f58aa3, - 0x00f39299, - 0x00f29592, - 0x00f19c8a, - 0x00f1a083, - 0x00efa77b, - 0x00eeaa73, - 0x00eead6b, - 0x00ecb463, - 0x00eab757, - 0x00e8bd4e, - 0x00e8c046, - 0x00e7c33d, - 0x00e5c835, - 0x00e5cb2c, - 0x00e3d023, - 0x00e1d31a, - 0x00dfd80d, - 0x00dfda04, - 0x00dcdc04, - 0x00dae10d, - 0x00dae316, - 0x00d8e71f, - 0x00d5e827, - 0x00d5ea30, - 0x00d3ee3d, - 0x00d0ef46, - 0x00cef24e, - 0x00cef357, - 0x00cbf65f, - 0x00c8f767, - 0x00c8f86f, - 0x00c6fa77, - 0x00c3fb83, - 0x00c0fc8a, - 0x00c0fd92, - 0x00bdfd99, - 0x00bafea0, - 0x00bafea7, - 0x00b7fead, - 0x00b4ffb4, - 0x00b1febd, - 0x00b1fec3, - 0x00adfec8, - 0x00aafdce, - 0x00aafdd3, - 0x00a7fbd8, - 0x00a3fbdc, - 0x00a3fae1, - 0x00a0f8e7, - 0x009cf7ea, - 0x0099f5ee, - 0x0099f3f1, - 0x0095f1f3, - 0x0092eff6, - 0x0092eef8, - 0x008eeafa, - 0x008ae8fc, - 0x0087e5fd, - 0x0087e3fe, - 0x0083e1fe, - 0x007fdcff, - 0x007fdafe, - 0x007bd5fe, - 0x0077d3fd, - 0x0073cefb, - 0x0073cbfa, - 0x006fc8f8, - 0x006bc3f6, - 0x006bc0f3, - 0x0067baf1, - 0x0063b7ee, - 0x0063b4ea, - 0x005fade5, - 0x005baae1, - 0x0057a3dc, - 0x0057a0d8, - 0x00539cd3, - 0x004e95ce, - 0x004e92c8, - 0x004a8ac3, - 0x004687ba, - 0x00417fb4, - 0x00417bad, - 0x003d77a7, - 0x00396fa0, - 0x00396b99, - 0x00356392, - 0x00305f8a, - 0x00305b7f, - 0x002c5377, - 0x00274e6f, - 0x00234667, - 0x0023415f, - 0x001f3957, - 0x001a354e, - 0x001a3046, - 0x00162739, - 0x00112330, - 0x000d1a27, - 0x000d161f, - 0x00081116, - 0x0004080d, - 0x00040404, - 0x00000404 -}; - -short plasma_sin1[] = { - 0, - 6, - 12, - 18, - 24, - 30, - 36, - 42, - 47, - 53, - 59, - 65, - 71, - 76, - 82, - 88, - 93, - 99, - 104, - 110, - 115, - 120, - 125, - 131, - 136, - 141, - 146, - 150, - 155, - 160, - 165, - 169, - 173, - 178, - 182, - 186, - 190, - 194, - 198, - 202, - 205, - 209, - 212, - 216, - 219, - 222, - 225, - 227, - 230, - 233, - 235, - 237, - 240, - 242, - 243, - 245, - 247, - 248, - 250, - 251, - 252, - 253, - 254, - 255, - 255, - 256, - 256, - 256, - 256, - 256, - 256, - 255, - 255, - 254, - 253, - 252, - 251, - 250, - 248, - 247, -}; - -short plasma_sin2[] = { - 0, - 4, - 9, - 13, - 17, - 21, - 24, - 27, - 29, - 30, - 32, - 32, - 32, - 31, - 30, - 28, - 25, - 22, - 19, - 15, - 11, - 7, - 2, - -2, - -7, - -11, - -15, - -19, - -22, - -25, - -28, - -30, - -31, - -32, - -32, - -32, - -30, - -29, - -27, - -24, - -21, - -17, - -13, - -9, - -4, - 0, - 4, - 9, - 13, - 17, - 21, - 24, - 27, - 29, - 30, - 32, - 32, - 32, - 31, - 30 -}; - -short plasma_sin3[] = { -0, - 4, - 9, - 13, - 18, - 22, - 26, - 30, - 34, - 38, - 41, - 44, - 48, - 50, - 53, - 55, - 58, - 59, - 61, - 62, - 63, - 64, - 64, - 64, - 64, - 63, - 62, - 61, - 59, - 58, - 55, - 53, - 50, - 48, - 44, - 41, - 38, - 34, - 30, - 26, - 22, - 18, - 13, - 9, - 4, - 0, - -4, - -9, - -13, - -18, - -22, - -26, - -30, - -34, - -38, - -41, - -44, - -48, - -50, - -53, - -55, - -58, - -59, - -61, - -62, - -63, - -64, - -64, - -64, - -64, - -63, - -62, - -61, - -59, - -58, - -55, - -53, - -50, - -48, - -44, - -41, - -38, - -34, - -30, - -26, - -22, - -18, - -13, - -9, - -4, -}; \ No newline at end of file diff --git a/examples/n00bdemo/plasma_tbl.h b/examples/n00bdemo/plasma_tbl.h deleted file mode 100644 index dd322e6..0000000 --- a/examples/n00bdemo/plasma_tbl.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _PLASMA_TBL_H -#define _PLASMA_TBL_H - -unsigned int plasma_colors[256]; -extern short plasma_sin1[]; -extern short plasma_sin2[]; -extern short plasma_sin3[]; - -#endif \ No newline at end of file diff --git a/examples/n00bdemo/plasmagen.s b/examples/n00bdemo/plasmagen.s deleted file mode 100644 index 07b3f48..0000000 --- a/examples/n00bdemo/plasmagen.s +++ /dev/null @@ -1,181 +0,0 @@ -.set noreorder - -.set POLYG4_tag, 0 -.set POLYG4_rgb0, 4 -.set POLYG4_xy0, 8 -.set POLYG4_rgb1, 12 -.set POLYG4_xy1, 16 -.set POLYG4_rgb2, 20 -.set POLYG4_xy2, 24 -.set POLYG4_rgb3, 28 -.set POLYG4_xy3, 32 -.set POLYG4_len, 36 - -# a0 - Plasma output -# a1 - Counter -.global genPlasma -.type genPlasma, @function -genPlasma: - move $t1, $0 - -.gn_y_loop: move $t0, $0 - -.gn_x_loop: la $v0, plasma_sin1 - sll $v1, $t0, 1 - addu $v1, $v0 - lh $v0, 0($v1) - - la $a2, plasma_sin2 - sll $v1, $t1, 1 - addu $v1, $a2 - lh $v1, 0($v1) - nop - add $v0, $v1 - - add $v1, $t0, $t1 - add $v1, $a1 - divu $v1, 90 - la $a2, plasma_sin3 - mfhi $v1 - - sll $v1, 1 - addu $v1, $a2 - lh $v1, 0($v1) - nop - add $v0, $v1 - - andi $v0, 0xff - - sb $v0, 0($a0) - addu $a0, 1 - - addiu $t0, 1 - blt $t0, 41, .gn_x_loop - nop - - addiu $t1, 1 - blt $t1, 31, .gn_y_loop - nop - - jr $ra - nop - - -# a0 - OT entry -# a1 - Primitive address -# a2 - Plasma map source -.global sortPlasma -.type sortPlasma, @function -sortPlasma: - move $t1, $0 - -.y_loop: - move $t0, $0 - -.x_loop: - lbu $v0, 0($a2) - addiu $a2, 1 - la $a3, plasma_colors - sll $v0, 2 - addu $v0, $a3 - lw $v0, 0($v0) - - lui $v1, 0x3800 - or $v0, $v1 - sw $v0, POLYG4_rgb0($a1) - - - lbu $v0, 0($a2) - nop - sll $v0, 2 - addu $v0, $a3 - lw $v0, 0($v0) - nop - sw $v0, POLYG4_rgb1($a1) - - - lbu $v0, 40($a2) - nop - sll $v0, 2 - addu $v0, $a3 - lw $v0, 0($v0) - nop - sw $v0, POLYG4_rgb2($a1) - - - lbu $v0, 41($a2) - nop - sll $v0, 2 - addu $v0, $a3 - lw $v0, 0($v0) - nop - sw $v0, POLYG4_rgb3($a1) - - - sll $v0, $t0, 4 - andi $v0, 0xffff - sll $v1, $t1, 20 - or $v0, $v1 - sw $v0, POLYG4_xy0($a1) - - sll $v0, $t0, 4 - andi $v0, 0xffff - addi $v0, 16 - sll $v1, $t1, 20 - or $v0, $v1 - sw $v0, POLYG4_xy1($a1) - - sll $v0, $t0, 4 - andi $v0, 0xffff - sll $v1, $t1, 4 - addi $v1, 16 - sll $v1, 16 - or $v0, $v1 - sw $v0, POLYG4_xy2($a1) - - sll $v0, $t0, 4 - andi $v0, 0xffff - addi $v0, 16 - sll $v1, $t1, 4 - addi $v1, 16 - sll $v1, 16 - or $v0, $v1 - sw $v0, POLYG4_xy3($a1) - - .set noat - - lui $v1, 0x0800 - lw $v0, 0($a0) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($a0) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($a0) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - addiu $a1, POLYG4_len - - - addiu $t0, 1 - blt $t0, 40, .x_loop - nop - - addiu $a2, 1 - addiu $t1, 1 - blt $t1, 30, .y_loop - nop - - - jr $ra - move $v0, $a1 \ No newline at end of file diff --git a/examples/n00bdemo/scrolltext.c b/examples/n00bdemo/scrolltext.c deleted file mode 100644 index e844f21..0000000 --- a/examples/n00bdemo/scrolltext.c +++ /dev/null @@ -1,136 +0,0 @@ -const char scroll_text[] = { -"Greetings! Lameguy64 proudly presents a new PlayStation homebrew demo called " -"n00bDEMO and is very much the first time I've released a new demo in years! The " -"last time I released a PlayStation demo was Meido-Demo back in 2013 and boy " -"does this new demo show how far I've gotten good at programming for the " -"PlayStation with graphical effects such as stencil masks and cel-shading " -"never before seen in demos that I'm aware of presented in hi-res mode at 60FPS " -"(50 if PAL). Though there's some flickering issues here and there (though it " -"probably flickers less in PAL mode and none on the PS2 and emulators) which " -"I'll explain the cause of such problems in a bit...\n" - -"Making this demo was pretty challenging (actually, mostly annoying) but " -"mostly for the wrong reasons because this demo is actually not made using " -"the official Sony SDK whatsoever. Yes, I actually put together my own SDK " -"using the GNU GCC toolchain and made the PlayStation GPU and GTE libraries " -"myself mostly in MIPS assembly. I call this SDK project of my own PSn00bSDK " -"and is probably the first homebrewn PlayStation SDK that can actually do 3D " -"graphics with full GTE support that is on-par to the official SDK even in " -"its current work-in-progress state as all other open source SDK examples I've " -"seen only offer very limited or no 3D capabilities whatsoever as with the case " -"of PSXSDK. I used n00b in the naming as I don't want to put pro in the name " -"of my projects knowing that its been used and abused in a lot of shovelware " -"and I wanted something less generic sounding. This SDK project is not exactly " -"professional software after all especially when I get into the issues I've had " -"with this project as of the making of this demo...\n" - -"Currently my SDK mostly offers support for the GPU and GTE but not so much on " -"other hardware features such as SPU, CD (which would be a disgrace not to support), " -"MDEC, controller/memory card and serial I/O. I mostly focused on supporting the " -"GPU and GTE as I feel it was the best way to present a proof of concept that making " -"an open source SDK that is on par to the official SDK should definitely be " -"possible especially when the ins and outs of the PlayStation hardware " -"had since been extensively documented so there's absolutely no excuse for not " -"supporting the hardware features of the console. I'm not certain if I'll continue " -"working on this PSn00bSDK project because I've experienced numerous issues with " -"this project, a lot of which appear to be compiler related (I'm using GCC " -"7.2.0 targetting mipsel-unknown-elf) as doing small code changes would sometimes break " -"or cripple certain parts of a large program that results to slowdown (hence " -"why there's some flicker and I had to omit the Lamelotl artwork in some scenes to " -"try to keep the flicker down) even when the code changes are completely unrelated to the " -"parts that got affected. Issues like these made developing this demo a MASSIVE " -"pain in the butt and it feels like things seem to stall more often than when using the " -"official SDK which also used GCC (2.8.1 to be specific). I'm not entirely sure if " -"they're optimization issues or I'm just pushing the console a little too far :). " -"I feel these issues are detrimental to this project as I don't really want to " -"work with a potentially unstable compiler in my SDK project as that would make " -"creating much larger projects (such as a full game) an even bigger pain " -"in the butt as things would break randomly over small code changes and having to " -"deal with such issues do not conform to my standards. I haven't checked if " -"GCC 8.2.0 has better mipsel support and I've yet to look into clang which is " -"said to support MIPS down to version 1 of the ISA.\n" - -"What I hoped to achieve with PSn00bSDK is to create a 100% free and open " -"source PlayStation SDK that is on-par to the official SDK to make homebrew " -"development for the PS1 much more attractive especially to those interested " -"in developing commercial homebrew for the console without the legal issues " -"surrounding the use of Sony's libraries. But considering the compiler issues " -"I've had and the PS1 community being mostly focussed on emulators and PSIO over " -"actually making homebrew for the console and many of the folks who actually knew how " -"to program for the console especially in low-level have either retired or " -"disappeared, making the feat I wanted to achieve with my SDK project somewhat " -"unlikely I feel. I'll be releasing source code of this demo and " -"the PSn00bSDK libraries on github a week or two as of the release of this " -"demo if things go according to plan on my end and contributions are accepted " -"for those interested to volunteer for this project...\n" - -"You should have noticed by now that there's something inherently missing " -"about this demo. Yes, there's no music in this demo at all. I would've " -"used some CD audio for music but I never got CD playback code working for " -"this demo and I've already made numerous attempts trying to crack the darn " -"thing with no success. At least there's no overused Kevin Macleod music here " -"unlike my last demo which I still wonder why I chose that for the music " -"over rendering out a MOD file into a WAV file and using that instead, man " -"was I stupid back then. Another option would be to use MOD music as I have " -"some SPU support in my SDK but writing my own MOD player would take a lot of " -"time and effort and finishing up this demo has taken long enough I feel as " -"I was originally going to release this demo back in December of 2018. " -"None of the existing MOD players can be used either as Hitmen's player " -"relies on Sony's libraries and is only offered in binary form (because " -"stupid) and PSXSDK's MOD player does all sample mixing in software instead " -"of using the SPU for playing the samples which is abslutely retarded and is " -"definitely not fit for this demo project. If you're watching this demo in " -"video form I've likely dubbed over some music to help keep things " -"interesting as you read this scroll text...\n" - -"There's actually some Scarlet Engine technology featured in this demo " -"namely the SMD model data format which is basically my own implementation " -"of the TMD model data for Scarlet and its drawing functions written in " -"assembly. The implementation featured here uses a newer revision of the SMD " -"model data and the drawing functions are a rewrite but they're still work " -"in progress as it currently does not support the features added in the new " -"revision of the SMD model data format. I haven't worked on Scarlet in awhile " -"as I've somewhat diverted to other things as of late and I've yet to do " -"research on better culling and rendering techniques as my last implementation " -"wasn't really all that good I feel. I plan to implement automated culling " -"using ray scanning when compiling a map and probably a geometry " -"LOD system similar to Spyro's engine. Developing Scarlet has been taking a " -"very long time I know but you have to consider this is being worked on by a " -"single person (who's probably a nobhead) as a hobby with no prior experience " -"in developing a 3D engine and to be honest, working on Scarlet feels a bit " -"too big for a single individual to work on. And in case you're wondering " -"about the apparent name change from Project Scarlet, that's because MS's new " -"Xbox is also codenamed Project Scarlet and I don't really like to have " -"Xbox fanboys looking desperately for videos about MS's Project Scarlet " -"and finding videos about my Project Scarlet instead that would only serve to " -"enrage them or something...\n" - -"Another piece of somewhat advanced technology used in this demo is that " -"all the assets in this demo are all stored in the PS-EXE in LZ77 compressed " -"form using my LZPack libraries to keep PS-EXE size low which speeds up the " -"boot time of this demo. I actually developed the LZPack library for the " -"official SDK in the past but I haven't got around to releasing them but I'm " -"likely going to include them with PSn00bSDK along with the compression/packing " -"tools and it should still work with the official SDK with only minor changes...\n" - -"I think that's pretty much all there is I wanted to say in this demo. I " -"was originally going to release this demo back in December of 2018 but " -"got delayed due to work and other things getting in the way but I hope " -"you enjoyed watching the visuals that were presented in this little " -"proof of concept demo...\n" - -"Greets to nocash NITROYUASH Orion danhans42 Shendo TriMesh " -"inc^lightforce Shadow\n" - -"Programming and most graphical assets in this demo are done by me " -"(Lameguy64). Lamelotl artwork drawn by Lumdrop. Hatkid from A Hat in " -"Time is owned by Gears for Breakfast and the 3D model featured in this " -"demo is made by me...\n" - -"Visit my website at http://lameguy64.tk if you want... " -"Pages are super lightweight with absolutely zero ads! (except joke ads that " -"don't do much other than mock the real ads, in case I've added them in the future)\n" - -"This has been a 2019 Meido-Tek Production!\n" - -}; \ No newline at end of file diff --git a/examples/n00bdemo/smd.h b/examples/n00bdemo/smd.h deleted file mode 100644 index 29c2812..0000000 --- a/examples/n00bdemo/smd.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef _SMD_H -#define _SMD_H - -typedef struct { - int *ot; - short otlen; - unsigned char zdiv,zoff; -} SC_OT; - -typedef struct { - char id[3]; - unsigned char version; - unsigned short flags; - unsigned short n_verts; - unsigned short n_norms; - unsigned short n_prims; - SVECTOR *p_verts; - SVECTOR *p_norms; - void *p_prims; -} SMD; - -typedef struct { - unsigned char type:2; - unsigned char l_type:2; - unsigned char c_type:1; - unsigned char texture:1; - unsigned char blend:2; - unsigned char zoff:4; - unsigned char nocull:1; - unsigned char mask:1; - unsigned char texwin:2; - unsigned char texoff:2; - unsigned char reserved:6; - unsigned char len; -} SMD_PRI_TYPE; - -typedef struct { - SMD_PRI_TYPE prim_id; - unsigned short v0,v1,v2,v3; // Vertex indices - unsigned short n0,n1,n2,n3; // Normal indices - unsigned char r0,g0,b0,code; // RGB0 - unsigned char r1,g1,b1,p0; // RGB1 - unsigned char r2,g2,b2,p1; // RGB2 - unsigned char r3,g3,b3,p2; // RGB3 - unsigned char tu0,tv0; - unsigned char tu1,tv1; - unsigned char tu2,tv2; - unsigned char tu3,tv3; - unsigned short tpage,clut; -} SMD_PRIM; - - -int OpenSMD(void *smd); -SMD_PRIM *ReadSMD(SMD_PRIM *pri); - -void scSetClipRect(int x0, int y0, int x1, int y1); - -SMD *smdInitData(void *data); -void smdSetBaseTPage(unsigned short tpage); - -char *smdSortModel(SC_OT *ot, char* pribuff, SMD *smd); -char *smdSortModelFlat(unsigned int *ot, char* pribuff, SMD *smd); - -void smdSetCelTex(unsigned short tpage, unsigned short clut); -void smdSetCelParam(int udiv, int vdiv, unsigned int col); -char *smdSortModelCel(SC_OT *ot, char* pribuff, SMD *smd); - -#endif \ No newline at end of file diff --git a/examples/n00bdemo/smd.s b/examples/n00bdemo/smd.s deleted file mode 100644 index f9cf2fe..0000000 --- a/examples/n00bdemo/smd.s +++ /dev/null @@ -1,924 +0,0 @@ -.set noreorder - -.include "gtereg.h" -.include "inline_s.h" -.include "smd_s.h" - - -.section .text - -# Currently does not do header checks -.global smdInitData -.type smdInitData, @function -smdInitData: - - lw $a1, SMD_HEAD_PVERTS($a0) # Initialize header pointers - lw $a2, SMD_HEAD_PNORMS($a0) - lw $a3, SMD_HEAD_PPRIMS($a0) - - addu $a1, $a0 - addu $a2, $a0 - addu $a3, $a0 - - sw $a1, SMD_HEAD_PVERTS($a0) - sw $a2, SMD_HEAD_PNORMS($a0) - sw $a3, SMD_HEAD_PPRIMS($a0) - - jr $ra - move $v0, $a0 - - -.global scSetClipRect -.type scSetClipRect, @function -scSetClipRect: - sll $a1, 16 - or $a0, $a1 - sll $a3, 16 - or $a2, $a3 - la $a1, _sc_clip - sw $a0, 0( $a1 ) - jr $ra - sw $a2, 4( $a1 ) - - -.global smdSetBaseTPage -.type smdSetBaseTPage, @function -smdSetBaseTPage: - la $v0, _smd_tpage_base - jr $ra - sw $a0, 0($v0) - - -.global smdSortModel -.type smdSortModel, @function -smdSortModel: - - # a0 - Pointer SC_OT structure - # a1 - Pointer to next primitive - # a2 - Pointer to SMD data address - # v0 - New pointer of primitive buffer (return) - - addiu $sp, -16 - sw $s0, 0($sp) - sw $s1, 4($sp) - sw $s2, 8($sp) - sw $s3, 12($sp) - - la $v0, _sc_clip - lw $t8, 0($v0) - lw $t9, 4($v0) - - lw $t0, OT_LEN($a0) - lw $a0, OT_ADDR($a0) - lw $t1, SMD_HEAD_PVERTS($a2) - lw $t2, SMD_HEAD_PNORMS($a2) - lw $t3, SMD_HEAD_PPRIMS($a2) - -.sort_loop: - - nop - lw $a3, 0($t3) # Get primitive ID word - move $t4, $t3 - - beqz $a3, .exit # Check if terminator (just zero) - addiu $t4, 4 - - lhu $t5, 0( $t4 ) # Load vertices - lhu $t6, 2( $t4 ) - lhu $t7, 4( $t4 ) - sll $t5, 3 - sll $t6, 3 - sll $t7, 3 - addu $t5, $t1 - addu $t6, $t1 - addu $t7, $t1 - lwc2 C2_VXY0, 0( $t5 ) - lwc2 C2_VZ0 , 4( $t5 ) - lwc2 C2_VXY1, 0( $t6 ) - lwc2 C2_VZ1 , 4( $t6 ) - lwc2 C2_VXY2, 0( $t7 ) - lwc2 C2_VZ2 , 4( $t7 ) - - srl $v1, $a3, 24 # Get primitive size - addu $t3, $v1 # Step main pointer to next primitive - - RTPT - - cfc2 $v0, C2_FLAG # Get GTE flag value - nop - - bltz $v0, .skip_prim # Skip primitive if Z overflow - andi $v0, $a3, 0x3 - - NCLIP # Backface culling - - srl $v1, $a3, 12 - andi $v1, 1 - - bnez $v1, .no_culling - nop - - mfc2 $v1, C2_MAC0 - nop - bltz $v1, .skip_prim - nop - -.no_culling: - - beq $v0, 0x1, .prim_tri # If primitive is a triangle - nop - beq $v0, 0x2, .prim_quad # If primitive is a quad - nop - - b .skip_prim - nop - -## Triangles - -.prim_tri: # Triangle processing - - addiu $t4, 8 # Advance from indices - - AVSZ3 # Calculate average Z - - srl $v0, $t0, 16 # Get Z divisor from OT_LEN value - andi $v0, 0xff - - mfc2 $t5, C2_OTZ # Get AVSZ3 result - - sra $v1, $t0, 24 # Get Z offset from OT_LEN value - - srl $t5, $v0 # Apply divisor and offset - sub $t5, $v1 - - blez $t5, .skip_prim # Skip primitive if less than zero - andi $v1, $t0, 0xffff - bge $t5, $v1, .skip_prim # Skip primitive if greater than OT length - sll $t5, 2 - addu $t5, $a0 # Append OTZ to OT address - - ClipTestTri - - and $v0, $s0, $s1 # v0 & v1 - beqz $v0, .do_draw - and $v0, $s1, $s2 # v1 & v2 - beqz $v0, .do_draw - and $v0, $s2, $s0 # v2 & v0 - beqz $v0, .do_draw - nop - b .skip_prim - nop - -.do_draw: - - - srl $v0, $a3, 2 # Lighting enabled? - andi $v0, 0x3 - bnez $v0, .F3_light - nop - - andi $v0, $a3, 0x10 # Gouraud shaded - bnez $v0, .F3_gouraud - nop - - andi $v0, $a3, 0x20 # Textured triangle - bnez $v0, .F3_textured - nop - - lw $v0, 0( $t4 ) # Flat color, no lighting - lui $v1, 0x2000 - or $v0, $v1 - - b .sort_F3_pri - sw $v0, POLYF3_rgbc( $a1 ) - -.F3_gouraud: - - lw $v0, 0($t4) - lw $v1, 4($t4) - .set noat - lui $at, 0x3000 - or $v0, $at - .set at - sw $v0, POLYG3_rgbc0($a1) - lw $v0, 8($t4) - sw $v1, POLYG3_rgbc1($a1) - b .sort_G3_pri - sw $v0, POLYG3_rgbc2($a1) - -.F3_textured: - - lw $v0, 0( $t4 ) # Flat color, no lighting - lui $v1, 0x2400 - or $v0, $v1 - sw $v0, POLYFT3_rgbc( $a1 ) - addiu $t4, 4 - - lhu $v0, 0( $t4 ) # Load texture coordinates - lhu $v1, 2( $t4 ) - sh $v0, POLYFT3_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYFT3_uv1( $a1 ) - sh $v0, POLYFT3_uv2( $a1 ) - - lw $v0, 8( $t4 ) # Tpage + CLUT - nop - andi $v1, $v0, 0xffff - sh $v1, POLYFT3_tpage( $a1 ) - srl $v0, 16 - - b .sort_FT3_pri - sh $v0, POLYFT3_clut( $a1 ) - -.F3_light: - - lhu $v0, 0( $t4 ) # Load normal 0 - - srl $v1, $a3, 2 - andi $v1, $v1, 0x3 - - sll $v0, 3 - addu $v0, $t2 - lwc2 C2_VXY0, 0( $v0 ) - lwc2 C2_VZ0 , 4( $v0 ) - - beq $v1, 0x2, .F3_light_smt - nop - - lw $v0, 4( $t4 ) - lui $v1, 0x2000 - or $v0, $v1 - mtc2 $v0, C2_RGB - - addiu $t4, 8 - nop - - NCCS - - andi $v0, $a3, 0x20 # Textured triangle - bnez $v0, .F3_light_tex - nop - - swc2 C2_RGB2, POLYF3_rgbc( $a1 ) - - b .sort_F3_pri - nop - -.F3_light_tex: - - lhu $v0, 0( $t4 ) # Load texture coordinates - lhu $v1, 2( $t4 ) - sh $v0, POLYFT3_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYFT3_uv1( $a1 ) - sh $v0, POLYFT3_uv2( $a1 ) - - lw $v1, 8( $t4 ) - nop - andi $v0, $v1, 0xffff - sh $v0, POLYFT3_tpage( $a1 ) - srl $v0, $v1, 16 - sh $v0, POLYFT3_clut( $a1 ) - - mfc2 $v0, C2_RGB2 - lui $v1, 0x2400 - or $v0, $v1 - - b .sort_FT3_pri - sw $v0, POLYFT3_rgbc( $a1 ) - -.F3_light_smt: - - lhu $v0, 2( $t4 ) # Load normals 1 and 2 - lhu $v1, 4( $t4 ) - sll $v0, 3 - sll $v1, 3 - addu $v0, $t2 - addu $v1, $t2 - lwc2 C2_VXY1, 0( $v0 ) - lwc2 C2_VZ1 , 4( $v0 ) - lw $v0, 8( $t4 ) - lwc2 C2_VXY2, 0( $v1 ) - lwc2 C2_VZ2 , 4( $v1 ) - lui $v1, 0x3000 # Load color - or $v0, $v1 - mtc2 $v0, C2_RGB - - addiu $t4, 12 - nop - - NCCT - - andi $v0, $a3, 0x20 # Textured triangle - bnez $v0, .F3_light_tex_smt - nop - - swc2 C2_RGB0, POLYG3_rgbc0( $a1 ) - swc2 C2_RGB1, POLYG3_rgbc1( $a1 ) - swc2 C2_RGB2, POLYG3_rgbc2( $a1 ) - - b .sort_G3_pri - nop - -.F3_light_tex_smt: - - lhu $v0, 0( $t4 ) # Load texture coordinates - lhu $v1, 2( $t4 ) - sh $v0, POLYGT3_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYGT3_uv1( $a1 ) - sh $v0, POLYGT3_uv2( $a1 ) - - lw $v1, 8( $t4 ) - nop - andi $v0, $v1, 0xffff - sh $v0, POLYGT3_tpage( $a1 ) - srl $v0, $v1, 16 - sh $v0, POLYGT3_clut( $a1 ) - - mfc2 $v0, C2_RGB0 - lui $v1, 0x3400 - or $v0, $v1 - - swc2 C2_RGB1, POLYGT3_rgbc1( $a1 ) - swc2 C2_RGB2, POLYGT3_rgbc2( $a1 ) - - b .sort_GT3_pri - sw $v0, POLYGT3_rgbc0( $a1 ) - -.sort_F3_pri: - - swc2 C2_SXY0, POLYF3_xy0($a1) - swc2 C2_SXY1, POLYF3_xy1($a1) - swc2 C2_SXY2, POLYF3_xy2($a1) - - la $v0, _smd_tpage_base - lhu $v0, 0($v0) - srl $v1, $a3, 6 # Get blend mode - andi $v1, 0x3 - sll $v1, 5 - or $v0, $v1 - lui $v1, 0xe100 - or $v0, $v1 - sw $v0, POLYF3_tpage($a1) # Store TPage - - .set noat - - lui $v1, 0x0500 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYF3_len - -.sort_FT3_pri: - - swc2 C2_SXY0, POLYFT3_xy0( $a1 ) - swc2 C2_SXY1, POLYFT3_xy1( $a1 ) - swc2 C2_SXY2, POLYFT3_xy2( $a1 ) - - .set noat - - lui $v1, 0x0700 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYFT3_len - -.sort_G3_pri: - - swc2 C2_SXY0, POLYG3_xy0( $a1 ) - swc2 C2_SXY1, POLYG3_xy1( $a1 ) - swc2 C2_SXY2, POLYG3_xy2( $a1 ) - - la $v0, _smd_tpage_base - lhu $v0, 0($v0) - srl $v1, $a3, 6 # Get blend mode - andi $v1, 0x3 - sll $v1, 5 - or $v0, $v1 - lui $v1, 0xe100 - or $v0, $v1 - sw $v0, POLYG3_tpage($a1) # Store TPage - - .set noat - - lui $v1, 0x0700 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYG3_len - -.sort_GT3_pri: - - swc2 C2_SXY0, POLYGT3_xy0( $a1 ) - swc2 C2_SXY1, POLYGT3_xy1( $a1 ) - swc2 C2_SXY2, POLYGT3_xy2( $a1 ) - - .set noat - - lui $v1, 0x0900 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYGT3_len - -## Quads - -.prim_quad: # Quad processing - - mfc2 $t6, C2_SXY0 # Retrieve first projected vertex - - lhu $t5, 6( $t4 ) # Project the last vertex - addiu $t4, 8 - sll $t5, 3 - addu $t5, $t1 - lwc2 C2_VXY0, 0( $t5 ) - lwc2 C2_VZ0 , 4( $t5 ) - - nRTPS - - cfc2 $v1, C2_FLAG # Get GTE flag value - - srl $v0, $t0, 16 # Get Z divisor from OT_LEN value - - bltz $v1, .skip_prim - nop - - AVSZ4 - - andi $v0, 0xff - - mfc2 $t5, C2_OTZ - - sra $v1, $t0, 24 # Get Z offset from OT_LEN value - - srl $t5, $v0 # Apply divisor and offset - sub $t5, $v1 - - blez $t5, .skip_prim # Skip primitive if less than zero - andi $v1, $t0, 0xffff - bge $t5, $v1, .skip_prim # Skip primitive if greater than OT length - sll $t5, 2 - addu $t5, $a0 # Append OTZ to OT address - - # no touch: - # a0, a1, a2, a3, t0, t1, t2, t3, t4, t5(ot), t6(sxy0) - - ClipTestQuad - - and $v0, $s0, $s1 # v0 & v1 - beqz $v0, .do_draw_q - and $v0, $s1, $s2 # v1 & v2 - beqz $v0, .do_draw_q - and $v0, $s2, $s3 # v2 & v3 - beqz $v0, .do_draw_q - and $v0, $s3, $s0 # v3 & v0 - beqz $v0, .do_draw_q - and $v0, $s0, $s2 # v0 & v2 - beqz $v0, .do_draw_q - and $v0, $s1, $s3 # v1 & v3 - beqz $v0, .do_draw_q - nop - b .skip_prim - nop - -.do_draw_q: - - srl $v0, $a3, 2 # Lighting enabled? - andi $v0, 0x3 - bnez $v0, .F4_light - nop - - andi $v0, $a3, 0x10 # Gouraud quad - bnez $v0, .F4_gouraud - nop - - andi $v0, $a3, 0x20 # Textured quad - bnez $v0, .F4_textured - nop - - lw $v0, 0($t4) - lui $v1, 0x2800 - or $v0, $v1 - - b .sort_F4_pri - sw $v0, POLYF4_rgbc($a1) - -.F4_gouraud: - - lw $v0, 0($t4) - lw $v1, 4($t4) - .set noat - lui $at, 0x3800 - or $v0, $at - .set at - sw $v0, POLYG4_rgbc0($a1) - lw $v0, 8($t4) - sw $v1, POLYG4_rgbc1($a1) - lw $v1, 12($t4) - sw $v0, POLYG4_rgbc2($a1) - b .sort_G4_pri - sw $v1, POLYG4_rgbc3($a1) - -.F4_textured: - - lw $v0, 0($t4) - lui $v1, 0x2c00 - or $v0, $v1 - sw $v0, POLYFT4_rgbc( $a1 ) - addiu $t4, 4 - - lhu $v0, 0($t4) # Load texture coordinates - lhu $v1, 2($t4) - sh $v0, POLYFT4_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYFT4_uv1( $a1 ) - lhu $v1, 6( $t4 ) - sh $v0, POLYFT4_uv2( $a1 ) - sh $v1, POLYFT4_uv3( $a1 ) - - lw $v1, 8( $t4 ) - nop - andi $v0, $v1, 0xffff - sh $v0, POLYFT4_tpage( $a1 ) - srl $v0, $v1, 16 - - b .sort_FT4_pri - sh $v0, POLYFT4_clut($a1) - -.F4_light: - - lhu $v0, 0( $t4 ) # Load normal 0 - - srl $v1, $a3, 2 - andi $v1, $v1, 0x3 - - sll $v0, 3 - addu $v0, $t2 - lwc2 C2_VXY0, 0( $v0 ) - lwc2 C2_VZ0 , 4( $v0 ) - - beq $v1, 0x2, .F4_light_smt - nop - - lw $v0, 4( $t4 ) - lui $v1, 0x2800 - or $v0, $v1 - mtc2 $v0, C2_RGB - - addiu $t4, 8 - nop - - NCCS - - andi $v0, $a3, 0x20 # Textured triangle - bnez $v0, .F4_light_tex - nop - - swc2 C2_RGB2, POLYF4_rgbc( $a1 ) - - b .sort_F4_pri - nop - -.F4_light_tex: - - lhu $v0, 0( $t4 ) # Load texture coordinates - lhu $v1, 2( $t4 ) - sh $v0, POLYFT4_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYFT4_uv1( $a1 ) - lhu $v1, 6( $t4 ) - sh $v0, POLYFT4_uv2( $a1 ) - sh $v1, POLYFT4_uv3( $a1 ) - - lw $v1, 8( $t4 ) - nop - andi $v0, $v1, 0xffff - sh $v0, POLYFT4_tpage( $a1 ) - srl $v0, $v1, 16 - sh $v0, POLYFT4_clut( $a1 ) - - mfc2 $v0, C2_RGB2 - lui $v1, 0x2c00 - or $v0, $v1 - - b .sort_FT4_pri - sw $v0, POLYFT4_rgbc( $a1 ) - -.F4_light_smt: - - lhu $v0, 2( $t4 ) # Load normals 1 and 2 - lhu $v1, 4( $t4 ) - sll $v0, 3 - sll $v1, 3 - addu $v0, $t2 - addu $v1, $t2 - lwc2 C2_VXY1, 0( $v0 ) - lwc2 C2_VZ1 , 4( $v0 ) - lwc2 C2_VXY2, 0( $v1 ) - lwc2 C2_VZ2 , 4( $v1 ) - - lw $v0, 8( $t4 ) - lui $v1, 0x3800 # Load color - or $v0, $v1 - mtc2 $v0, C2_RGB - - nNCCT - - lhu $v0, 6( $t4 ) # Load normal 3 - - addiu $t4, 12 - - sll $v0, 3 - addu $v0, $t2 - lwc2 C2_VXY0, 0( $v0 ) - lwc2 C2_VZ0 , 4( $v0 ) - - andi $v0, $a3, 0x20 # Textured triangle - bnez $v0, .F4_light_tex_smt - nop - - swc2 C2_RGB0, POLYG4_rgbc0( $a1 ) - swc2 C2_RGB1, POLYG4_rgbc1( $a1 ) - swc2 C2_RGB2, POLYG4_rgbc2( $a1 ) - - nNCCS - - swc2 C2_RGB2, POLYG4_rgbc3( $a1 ) - - b .sort_G4_pri - nop - -.F4_light_tex_smt: - - mfc2 $v0, C2_RGB0 - lui $v1, 0x3400 - or $v0, $v1 - sw $v0, POLYGT4_rgbc0( $a1 ) - swc2 C2_RGB1, POLYGT4_rgbc1( $a1 ) - swc2 C2_RGB2, POLYGT4_rgbc2( $a1 ) - - NCCS - - lhu $v0, 0( $t4 ) # Load texture coordinates - lhu $v1, 2( $t4 ) - sh $v0, POLYGT4_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYGT4_uv1( $a1 ) - lhu $v1, 6( $t4 ) - sh $v0, POLYGT4_uv2( $a1 ) - sh $v1, POLYGT4_uv3( $a1 ) - - lw $v1, 8( $t4 ) - swc2 C2_RGB2, POLYGT4_rgbc3( $a1 ) - - andi $v0, $v1, 0xffff - sh $v0, POLYGT4_tpage( $a1 ) - srl $v0, $v1, 16 - - b .sort_GT4_pri - sh $v0, POLYGT4_clut( $a1 ) - -.sort_F4_pri: - - sw $t6, POLYF4_xy0($a1) - swc2 C2_SXY0, POLYF4_xy1($a1) - swc2 C2_SXY1, POLYF4_xy2($a1) - swc2 C2_SXY2, POLYF4_xy3($a1) - - la $v0, _smd_tpage_base - lhu $v0, 0($v0) - srl $v1, $a3, 6 # Get blend mode - andi $v1, 0x3 - sll $v1, 5 - or $v0, $v1 - lui $v1, 0xe100 - or $v0, $v1 - sw $v0, POLYF4_tpage($a1) # Store TPage - - .set noat - - lui $v1, 0x0600 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYF4_len - -.sort_FT4_pri: - - sw $t6, POLYFT4_xy0($a1) - swc2 C2_SXY0, POLYFT4_xy1($a1) - swc2 C2_SXY1, POLYFT4_xy2($a1) - swc2 C2_SXY2, POLYFT4_xy3($a1) - - .set noat - - lui $v1, 0x0900 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYFT4_len - -.sort_G4_pri: - - sw $t6, POLYG4_xy0($a1) - swc2 C2_SXY0, POLYG4_xy1($a1) - swc2 C2_SXY1, POLYG4_xy2($a1) - swc2 C2_SXY2, POLYG4_xy3($a1) - - la $v0, _smd_tpage_base - lhu $v0, 0($v0) - srl $v1, $a3, 6 # Get blend mode - andi $v1, 0x3 - sll $v1, 5 - or $v0, $v1 - lui $v1, 0xe100 - or $v0, $v1 - sw $v0, POLYG4_tpage($a1) # Store TPage - - .set noat - - lui $v1, 0x0900 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYG4_len - -.sort_GT4_pri: - - sw $t6, POLYGT4_xy0($a1) - swc2 C2_SXY0, POLYGT4_xy1($a1) - swc2 C2_SXY1, POLYGT4_xy2($a1) - swc2 C2_SXY2, POLYGT4_xy3($a1) - - .set noat - - lui $v1, 0x0c00 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYGT4_len - -.skip_prim: - - b .sort_loop - nop - -.exit: - - lw $s0, 0( $sp ) - lw $s1, 4( $sp ) - lw $s2, 8( $sp ) - lw $s3, 12( $sp ) - addiu $sp, 16 - jr $ra - move $v0, $a1 - - -.comm _smd_tpage_base, 4, 4 - -.comm _sc_clip, 8, 4 diff --git a/examples/n00bdemo/smd_cel.s b/examples/n00bdemo/smd_cel.s deleted file mode 100644 index ece0dd8..0000000 --- a/examples/n00bdemo/smd_cel.s +++ /dev/null @@ -1,1073 +0,0 @@ -.set noreorder - -.include "gtereg.h" -.include "inline_s.h" -.include "smd_s.h" - - -.section .text - -.global smdSetCelTex -.type smdSetCelTex, @function -smdSetCelTex: - # a0 - TPage value - # a1 - CLUT value - la $v0, _smd_cel_tpage - andi $a0, 0xffff - sll $a1, 16 - or $a0, $a1 - jr $ra - sw $a0, 0($v0) - - - -.global smdSetCelParam -.type smdSetCelParam, @function -smdSetCelParam: - # a0 - Shading texture U offset - # a1 - Shading texture V offset - # a2 - Shading primitive color - andi $a1, 0xff - sll $a1, 8 - andi $a0, 0xff - or $a0, $a1 - la $v0, _smd_cel_param - sw $a0, 0($v0) - la $v0, _smd_cel_col - lui $v1, 0x0200 - or $a3, $v1 - jr $ra - sw $a2, 0($v0) - - -.global smdSortModelCel -.type smdSortModelCel, @function -smdSortModelCel: - - # a0 - Pointer SC_OT structure - # a1 - Pointer to next primitive - # a2 - Pointer to SMD data address - # v0 - New pointer of primitive buffer (return) - - addiu $sp, -16 - sw $s0, 0($sp) - sw $s1, 4($sp) - sw $s2, 8($sp) - sw $s3, 12($sp) - - la $v0, _sc_clip - lw $t8, 0($v0) - lw $t9, 4($v0) - - lw $t0, OT_LEN($a0) - lw $a0, OT_ADDR($a0) - lw $t1, SMD_HEAD_PVERTS($a2) - lw $t2, SMD_HEAD_PNORMS($a2) - lw $t3, SMD_HEAD_PPRIMS($a2) - -.sort_loop: - - nop - lw $a3, 0($t3) # Get primitive ID word - move $t4, $t3 - - beqz $a3, .exit # Check if terminator (just zero) - addiu $t4, 4 - - lhu $t5, 0( $t4 ) # Load vertices - lhu $t6, 2( $t4 ) - lhu $t7, 4( $t4 ) - sll $t5, 3 - sll $t6, 3 - sll $t7, 3 - addu $t5, $t1 - addu $t6, $t1 - addu $t7, $t1 - lwc2 C2_VXY0, 0( $t5 ) - lwc2 C2_VZ0 , 4( $t5 ) - lwc2 C2_VXY1, 0( $t6 ) - lwc2 C2_VZ1 , 4( $t6 ) - lwc2 C2_VXY2, 0( $t7 ) - lwc2 C2_VZ2 , 4( $t7 ) - - srl $v1, $a3, 24 # Get primitive size - addu $t3, $v1 # Step main pointer to next primitive - - RTPT - - cfc2 $v0, C2_FLAG # Get GTE flag value - nop - - bltz $v0, .skip_prim # Skip primitive if Z overflow - andi $v0, $a3, 0x3 - - NCLIP # Backface culling - - srl $v1, $a3, 12 - andi $v1, 1 - - bnez $v1, .no_culling - nop - - mfc2 $v1, C2_MAC0 - nop - bltz $v1, .skip_prim - nop - -.no_culling: - - beq $v0, 0x1, .prim_tri # If primitive is a triangle - nop - beq $v0, 0x2, .prim_quad # If primitive is a quad - nop - - b .skip_prim - nop - -## Triangles - -.prim_tri: # Triangle processing - - addiu $t4, 8 # Advance from indices - - AVSZ3 # Calculate average Z - - srl $v0, $t0, 16 # Get Z divisor from OT_LEN value - andi $v0, 0xff - - mfc2 $t5, C2_OTZ # Get AVSZ3 result - - sra $v1, $t0, 24 # Get Z offset from OT_LEN value - - srl $t5, $v0 # Apply divisor and offset - sub $t5, $v1 - - blez $t5, .skip_prim # Skip primitive if less than zero - andi $v1, $t0, 0xffff - bge $t5, $v1, .skip_prim # Skip primitive if greater than OT length - sll $t5, 2 - addu $t5, $a0 # Append OTZ to OT address - - ClipTestTri - - and $v0, $s0, $s1 # v0 & v1 - beqz $v0, .do_draw - and $v0, $s1, $s2 # v1 & v2 - beqz $v0, .do_draw - and $v0, $s2, $s0 # v2 & v0 - beqz $v0, .do_draw - nop - b .skip_prim - nop - -.do_draw: - - - srl $v0, $a3, 2 # Lighting enabled? - andi $v0, 0x3 - bnez $v0, .F3_light - nop - - andi $v0, $a3, 0x10 # Gouraud shaded - bnez $v0, .F3_gouraud - nop - - andi $v0, $a3, 0x20 # Textured triangle - bnez $v0, .F3_textured - nop - - lw $v0, 0( $t4 ) # Flat color, no lighting - lui $v1, 0x2000 - or $v0, $v1 - - b .sort_F3_pri - sw $v0, POLYF3_rgbc( $a1 ) - -.F3_gouraud: - - lw $v0, 0($t4) - lw $v1, 4($t4) - .set noat - lui $at, 0x3000 - or $v0, $at - .set at - sw $v0, POLYG3_rgbc0($a1) - lw $v0, 8($t4) - sw $v1, POLYG3_rgbc1($a1) - b .sort_G3_pri - sw $v0, POLYG3_rgbc2($a1) - -.F3_textured: - - lw $v0, 0( $t4 ) # Flat color, no lighting - lui $v1, 0x2400 - or $v0, $v1 - sw $v0, POLYFT3_rgbc( $a1 ) - addiu $t4, 4 - - lhu $v0, 0( $t4 ) # Load texture coordinates - lhu $v1, 2( $t4 ) - sh $v0, POLYFT3_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYFT3_uv1( $a1 ) - sh $v0, POLYFT3_uv2( $a1 ) - - lw $v0, 8( $t4 ) # Tpage + CLUT - nop - andi $v1, $v0, 0xffff - sh $v1, POLYFT3_tpage( $a1 ) - srl $v0, 16 - - b .sort_FT3_pri - sh $v0, POLYFT3_clut( $a1 ) - -.F3_light: - - lhu $v0, 0( $t4 ) # Load normal 0 - - srl $v1, $a3, 2 - andi $v1, $v1, 0x3 - - sll $v0, 3 - addu $v0, $t2 - lwc2 C2_VXY0, 0( $v0 ) - lwc2 C2_VZ0 , 4( $v0 ) - - beq $v1, 0x2, .F3_light_smt - nop - - lw $v0, 4( $t4 ) - lui $v1, 0x2000 - or $v0, $v1 - mtc2 $v0, C2_RGB - - addiu $t4, 8 - nop - - NCCS - - andi $v0, $a3, 0x20 # Textured triangle - bnez $v0, .F3_light_tex - nop - - swc2 C2_RGB2, POLYF3_rgbc( $a1 ) - - b .sort_F3_pri - nop - -.F3_light_tex: - - lhu $v0, 0( $t4 ) # Load texture coordinates - lhu $v1, 2( $t4 ) - sh $v0, POLYFT3_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYFT3_uv1( $a1 ) - sh $v0, POLYFT3_uv2( $a1 ) - - lw $v1, 8( $t4 ) - nop - andi $v0, $v1, 0xffff - sh $v0, POLYFT3_tpage( $a1 ) - srl $v0, $v1, 16 - sh $v0, POLYFT3_clut( $a1 ) - - mfc2 $v0, C2_RGB2 - lui $v1, 0x2400 - or $v0, $v1 - - b .sort_FT3_pri - sw $v0, POLYFT3_rgbc( $a1 ) - -.F3_light_smt: - - lhu $v0, 2($t4) # Load normals 1 and 2 - lhu $v1, 4($t4) - sll $v0, 3 - sll $v1, 3 - addu $v0, $t2 - addu $v1, $t2 - lwc2 C2_VXY1, 0($v0) - lwc2 C2_VZ1 , 4($v0) - #la $v0, _smd_cel_col - #lw $v0, 0($v0) - lwc2 C2_VXY2, 0($v1) - lwc2 C2_VZ2 , 4($v1) - mtc2 $v0, C2_RGB - - swc2 C2_SXY0, POLYFT3_xy0($a1) - swc2 C2_SXY1, POLYFT3_xy1($a1) - swc2 C2_SXY2, POLYFT3_xy2($a1) - - la $v0, _smd_cel_tpage # Load cel shader TPage and CLUT values - lw $v0, 0($v0) - - NCT - - andi $v1, $v0, 0xffff - sh $v1, POLYFT3_tpage($a1) - srl $v1, $v0, 16 - sh $v1, POLYFT3_clut($a1) - - # Usable regs: v0, v1, at, t6, t7 - - .set noat - - la $at, _smd_cel_param # Load cel shader parameters - lhu $at, 0($at) - - mfc2 $t7, C2_RGB0 # Get first shaded color - andi $v1, $at, 0xff # Get U divisor value - andi $t7, 0xffff # Only keep R and G colors - - andi $v0, $t7, 0xff # U0 - srl $v0, $v1 - sb $v0, POLYFT3_uv0($a1) - srl $v0, $t7, 8 # V0 - srl $v1, $at, 8 - srl $v0, $v1 - sb $v0, POLYFT3_uv0+1($a1) - - mfc2 $t7, C2_RGB1 - andi $v1, $at, 0xff - andi $t7, 0xffff - andi $v0, $t7, 0xff # U1 - srl $v0, $v1 - sb $v0, POLYFT3_uv1($a1) - srl $v0, $t7, 8 # V1 - srl $v1, $at, 8 - srl $v0, $v1 - sb $v0, POLYFT3_uv1+1($a1) - - mfc2 $t7, C2_RGB2 - andi $v1, $at, 0xff - andi $t7, 0xffff - andi $v0, $t7, 0xff # U2 - srl $v0, $v1 - sb $v0, POLYFT3_uv2($a1) - srl $v0, $t7, 8 # V2 - srl $v1, $at, 8 - srl $v0, $v1 - sb $v0, POLYFT3_uv2+1($a1) - - la $v0, _smd_cel_col - lw $v0, 0($v0) - lui $v1, 0x2600 - or $v0, $v1 - sw $v0, POLYFT3_rgbc($a1) - - lw $t7, 8($t4) - addiu $t4, 12 - - lui $v1, 0x0700 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $v1, $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $v1 - sw $v0, 0($t5) - - lui $v0, 0x8000 - or $a1, $v0 - addiu $a1, POLYFT3_len - - .set at - - andi $v0, $a3, 0x20 # Textured triangle - bnez $v0, .F3_light_tex_smt - nop - - #swc2 C2_RGB0, POLYG3_rgbc0( $a1 ) - #swc2 C2_RGB1, POLYG3_rgbc1( $a1 ) - #swc2 C2_RGB2, POLYG3_rgbc2( $a1 ) - - lui $v0, 0x2000 - or $t7, $v0 - b .sort_F3_pri - sw $t7, POLYF3_rgbc($a1) - -.F3_light_tex_smt: - - lhu $v0, 0( $t4 ) # Load texture coordinates - lhu $v1, 2( $t4 ) - sh $v0, POLYFT3_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYFT3_uv1( $a1 ) - sh $v0, POLYFT3_uv2( $a1 ) - - lw $v1, 8( $t4 ) - nop - andi $v0, $v1, 0xffff - sh $v0, POLYFT3_tpage( $a1 ) - srl $v0, $v1, 16 - sh $v0, POLYFT3_clut( $a1 ) - - lui $v1, 0x2400 - or $t7, $v1 - - b .sort_FT3_pri - sw $t7, POLYFT3_rgbc( $a1 ) - -.sort_F3_pri: - - swc2 C2_SXY0, POLYF3_xy0($a1) - swc2 C2_SXY1, POLYF3_xy1($a1) - swc2 C2_SXY2, POLYF3_xy2($a1) - - la $v0, _smd_tpage_base - lhu $v0, 0($v0) - srl $v1, $a3, 6 # Get blend mode - andi $v1, 0x3 - sll $v1, 5 - or $v0, $v1 - lui $v1, 0xe100 - or $v0, $v1 - sw $v0, POLYF3_tpage($a1) # Store TPage - - .set noat - - lui $v1, 0x0500 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYF3_len - -.sort_FT3_pri: - - swc2 C2_SXY0, POLYFT3_xy0( $a1 ) - swc2 C2_SXY1, POLYFT3_xy1( $a1 ) - swc2 C2_SXY2, POLYFT3_xy2( $a1 ) - - .set noat - - lui $v1, 0x0700 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYFT3_len - -.sort_G3_pri: - - swc2 C2_SXY0, POLYG3_xy0( $a1 ) - swc2 C2_SXY1, POLYG3_xy1( $a1 ) - swc2 C2_SXY2, POLYG3_xy2( $a1 ) - - la $v0, _smd_tpage_base - lhu $v0, 0($v0) - srl $v1, $a3, 6 # Get blend mode - andi $v1, 0x3 - sll $v1, 5 - or $v0, $v1 - lui $v1, 0xe100 - or $v0, $v1 - sw $v0, POLYG3_tpage($a1) # Store TPage - - .set noat - - lui $v1, 0x0700 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYG3_len - -.sort_GT3_pri: - - swc2 C2_SXY0, POLYGT3_xy0( $a1 ) - swc2 C2_SXY1, POLYGT3_xy1( $a1 ) - swc2 C2_SXY2, POLYGT3_xy2( $a1 ) - - .set noat - - lui $v1, 0x0900 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYGT3_len - -## Quads - -.prim_quad: # Quad processing - - mfc2 $t6, C2_SXY0 # Retrieve first projected vertex - - lhu $t5, 6( $t4 ) # Project the last vertex - addiu $t4, 8 - sll $t5, 3 - addu $t5, $t1 - lwc2 C2_VXY0, 0( $t5 ) - lwc2 C2_VZ0 , 4( $t5 ) - - nRTPS - - cfc2 $v1, C2_FLAG # Get GTE flag value - - srl $v0, $t0, 16 # Get Z divisor from OT_LEN value - - bltz $v1, .skip_prim - nop - - AVSZ4 - - andi $v0, 0xff - - mfc2 $t5, C2_OTZ - - sra $v1, $t0, 24 # Get Z offset from OT_LEN value - - srl $t5, $v0 # Apply divisor and offset - sub $t5, $v1 - - blez $t5, .skip_prim # Skip primitive if less than zero - andi $v1, $t0, 0xffff - bge $t5, $v1, .skip_prim # Skip primitive if greater than OT length - sll $t5, 2 - addu $t5, $a0 # Append OTZ to OT address - - # no touch: - # a0, a1, a2, a3, t0, t1, t2, t3, t4, t5(ot), t6(sxy0) - - ClipTestQuad - - and $v0, $s0, $s1 # v0 & v1 - beqz $v0, .do_draw_q - and $v0, $s1, $s2 # v1 & v2 - beqz $v0, .do_draw_q - and $v0, $s2, $s3 # v2 & v3 - beqz $v0, .do_draw_q - and $v0, $s3, $s0 # v3 & v0 - beqz $v0, .do_draw_q - and $v0, $s0, $s2 # v0 & v2 - beqz $v0, .do_draw_q - and $v0, $s1, $s3 # v1 & v3 - beqz $v0, .do_draw_q - nop - b .skip_prim - nop - -.do_draw_q: - - srl $v0, $a3, 2 # Lighting enabled? - andi $v0, 0x3 - bnez $v0, .F4_light - nop - - andi $v0, $a3, 0x10 # Gouraud quad - bnez $v0, .F4_gouraud - nop - - andi $v0, $a3, 0x20 # Textured quad - bnez $v0, .F4_textured - nop - - lw $v0, 0($t4) - lui $v1, 0x2800 - or $v0, $v1 - - b .sort_F4_pri - sw $v0, POLYF4_rgbc($a1) - -.F4_gouraud: - - lw $v0, 0($t4) - lw $v1, 4($t4) - .set noat - lui $at, 0x3800 - or $v0, $at - .set at - sw $v0, POLYG4_rgbc0($a1) - lw $v0, 8($t4) - sw $v1, POLYG4_rgbc1($a1) - lw $v1, 12($t4) - sw $v0, POLYG4_rgbc2($a1) - b .sort_G4_pri - sw $v1, POLYG4_rgbc3($a1) - -.F4_textured: - - lw $v0, 0($t4) - lui $v1, 0x2c00 - or $v0, $v1 - sw $v0, POLYFT4_rgbc( $a1 ) - addiu $t4, 4 - - lhu $v0, 0($t4) # Load texture coordinates - lhu $v1, 2($t4) - sh $v0, POLYFT4_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYFT4_uv1( $a1 ) - lhu $v1, 6( $t4 ) - sh $v0, POLYFT4_uv2( $a1 ) - sh $v1, POLYFT4_uv3( $a1 ) - - lw $v1, 8( $t4 ) - nop - andi $v0, $v1, 0xffff - sh $v0, POLYFT4_tpage( $a1 ) - srl $v0, $v1, 16 - - b .sort_FT4_pri - sh $v0, POLYFT4_clut($a1) - -.F4_light: - - lhu $v0, 0( $t4 ) # Load normal 0 - - srl $v1, $a3, 2 - andi $v1, $v1, 0x3 - - sll $v0, 3 - addu $v0, $t2 - lwc2 C2_VXY0, 0( $v0 ) - lwc2 C2_VZ0 , 4( $v0 ) - - beq $v1, 0x2, .F4_light_smt - nop - - lw $v0, 4( $t4 ) - lui $v1, 0x2800 - or $v0, $v1 - mtc2 $v0, C2_RGB - - addiu $t4, 8 - nop - - NCS - - andi $v0, $a3, 0x20 # Textured triangle - bnez $v0, .F4_light_tex - nop - - swc2 C2_RGB2, POLYF4_rgbc( $a1 ) - - b .sort_F4_pri - nop - -.F4_light_tex: - - lhu $v0, 0( $t4 ) # Load texture coordinates - lhu $v1, 2( $t4 ) - sh $v0, POLYFT4_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYFT4_uv1( $a1 ) - lhu $v1, 6( $t4 ) - sh $v0, POLYFT4_uv2( $a1 ) - sh $v1, POLYFT4_uv3( $a1 ) - - lw $v1, 8( $t4 ) - nop - andi $v0, $v1, 0xffff - sh $v0, POLYFT4_tpage( $a1 ) - srl $v0, $v1, 16 - sh $v0, POLYFT4_clut( $a1 ) - - mfc2 $v0, C2_RGB2 - lui $v1, 0x2c00 - or $v0, $v1 - - b .sort_FT4_pri - nop - sw $v0, POLYFT4_rgbc( $a1 ) - -.F4_light_smt: - - lhu $v0, 2( $t4 ) # Load normals 1 and 2 - lhu $v1, 4( $t4 ) - sll $v0, 3 - sll $v1, 3 - addu $v0, $t2 - addu $v1, $t2 - lwc2 C2_VXY1, 0( $v0 ) - lwc2 C2_VZ1 , 4( $v0 ) - lwc2 C2_VXY2, 0( $v1 ) - lwc2 C2_VZ2 , 4( $v1 ) - - sw $t6, POLYFT4_xy0($a1) - swc2 C2_SXY0, POLYFT4_xy1($a1) - swc2 C2_SXY1, POLYFT4_xy2($a1) - swc2 C2_SXY2, POLYFT4_xy3($a1) - - la $v0, _smd_cel_tpage # Load cel shader TPage and CLUT values - lw $v0, 0($v0) - - NCT - - andi $v1, $v0, 0xffff - sh $v1, POLYFT4_tpage($a1) - srl $v1, $v0, 16 - sh $v1, POLYFT4_clut($a1) - - # Usable regs: v0, v1, at, t7 - - .set noat - - la $at, _smd_cel_param # Load cel shader parameters - lhu $at, 0($at) - - mfc2 $t7, C2_RGB0 - andi $v1, $at, 0xff # Get U divisor value - andi $t7, 0xffff # Only keep R and G colors - - andi $v0, $t7, 0xff # U0 - srl $v0, $v1 - sb $v0, POLYFT4_uv0($a1) - srl $v0, $t7, 8 # V0 - srl $v1, $at, 8 - srl $v0, $v1 - sb $v0, POLYFT4_uv0+1($a1) - - mfc2 $t7, C2_RGB1 - andi $v1, $at, 0xff - andi $t7, 0xffff - andi $v0, $t7, 0xff # U1 - srl $v0, $v1 - sb $v0, POLYFT4_uv1($a1) - srl $v0, $t7, 8 # V1 - srl $v1, $at, 8 - srl $v0, $v1 - sb $v0, POLYFT4_uv1+1($a1) - - mfc2 $t7, C2_RGB2 - andi $v1, $at, 0xff - andi $t7, 0xffff - andi $v0, $t7, 0xff # U2 - srl $v0, $v1 - sb $v0, POLYFT4_uv2($a1) - srl $v0, $t7, 8 # V2 - srl $v1, $at, 8 - srl $v0, $v1 - sb $v0, POLYFT4_uv2+1($a1) - - la $v0, _smd_cel_col - lw $v0, 0($v0) - lui $v1, 0x2E00 - or $v0, $v1 - sw $v0, POLYFT4_rgbc($a1) - - lw $t7, 8($t4) - - lhu $v0, 6($t4) # Load normal 3 - addiu $t4, 12 - sll $v0, 3 - addu $v0, $t2 - lwc2 C2_VXY0, 0( $v0 ) - lwc2 C2_VZ0 , 4( $v0 ) - - nNCS - - mfc2 $s0, C2_RGB2 - andi $v1, $at, 0xff - andi $s0, 0xffff - andi $v0, $s0, 0xff # U3 - srl $v0, $v1 - sb $v0, POLYFT4_uv3($a1) - srl $v0, $s0, 8 # V3 - srl $v1, $at, 8 - srl $v0, $v1 - sb $v0, POLYFT4_uv3+1($a1) - - lui $v1, 0x0900 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $v1, $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $v1 - sw $v0, 0($t5) - - lui $v0, 0x8000 - or $a1, $v0 - addiu $a1, POLYFT4_len - - .set at - - andi $v0, $a3, 0x20 # Textured quad - bnez $v0, .F4_light_tex_smt - nop - - lui $v0, 0x2800 - or $t7, $v0 - b .sort_F4_pri - sw $t7, POLYF4_rgbc($a1) - -.F4_light_tex_smt: - - lhu $v0, 0($t4) # Load texture coordinates - lhu $v1, 2($t4) - sh $v0, POLYFT4_uv0($a1) - lhu $v0, 4($t4) - sh $v1, POLYFT4_uv1($a1) - lhu $v1, 6($t4) - sh $v0, POLYFT4_uv2($a1) - sh $v1, POLYFT4_uv3($a1) - - lw $v1, 8($t4) - - lui $v0, 0x2E00 - or $t7, $v0 - sw $t7, POLYFT4_rgbc($a1) - - andi $v0, $v1, 0xffff - sh $v0, POLYFT4_tpage($a1) - srl $v0, $v1, 16 - - b .sort_FT4_pri - sh $v0, POLYFT4_clut($a1) - -.sort_F4_pri: - - sw $t6, POLYF4_xy0($a1) - swc2 C2_SXY0, POLYF4_xy1($a1) - swc2 C2_SXY1, POLYF4_xy2($a1) - swc2 C2_SXY2, POLYF4_xy3($a1) - - la $v0, _smd_tpage_base - lhu $v0, 0($v0) - srl $v1, $a3, 6 # Get blend mode - andi $v1, 0x3 - sll $v1, 5 - or $v0, $v1 - lui $v1, 0xe100 - or $v0, $v1 - sw $v0, POLYF4_tpage($a1) # Store TPage - - .set noat - - lui $v1, 0x0600 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYF4_len - -.sort_FT4_pri: - - sw $t6, POLYFT4_xy0($a1) - swc2 C2_SXY0, POLYFT4_xy1($a1) - swc2 C2_SXY1, POLYFT4_xy2($a1) - swc2 C2_SXY2, POLYFT4_xy3($a1) - - .set noat - - lui $v1, 0x0900 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYFT4_len - -.sort_G4_pri: - - sw $t6, POLYG4_xy0($a1) - swc2 C2_SXY0, POLYG4_xy1($a1) - swc2 C2_SXY1, POLYG4_xy2($a1) - swc2 C2_SXY2, POLYG4_xy3($a1) - - la $v0, _smd_tpage_base - lhu $v0, 0($v0) - srl $v1, $a3, 6 # Get blend mode - andi $v1, 0x3 - sll $v1, 5 - or $v0, $v1 - lui $v1, 0xe100 - or $v0, $v1 - sw $v0, POLYG4_tpage($a1) # Store TPage - - .set noat - - lui $v1, 0x0900 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYG4_len - -.sort_GT4_pri: - - sw $t6, POLYGT4_xy0($a1) - swc2 C2_SXY0, POLYGT4_xy1($a1) - swc2 C2_SXY1, POLYGT4_xy2($a1) - swc2 C2_SXY2, POLYGT4_xy3($a1) - - .set noat - - lui $v1, 0x0c00 - lw $v0, 0($t5) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($t5) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($t5) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYGT4_len - -.skip_prim: - - b .sort_loop - nop - -.exit: - - lw $s0, 0( $sp ) - lw $s1, 4( $sp ) - lw $s2, 8( $sp ) - lw $s3, 12( $sp ) - addiu $sp, 16 - jr $ra - move $v0, $a1 - - -.comm _smd_cel_col, 4, 4 # STP shading polygon color -.comm _smd_cel_param, 4, 4 # U divisor, V divisor, shading clip -.comm _smd_cel_tpage, 4, 4 # CEL shader texture page & CLUT - diff --git a/examples/n00bdemo/smd_flat.s b/examples/n00bdemo/smd_flat.s deleted file mode 100644 index 0d48c63..0000000 --- a/examples/n00bdemo/smd_flat.s +++ /dev/null @@ -1,832 +0,0 @@ -.set noreorder - -.include "gtereg.h" -.include "inline_s.h" -.include "smd_s.h" - - -.section .text - -.global smdSortModelFlat -.type smdSortModelFlat, @function -smdSortModelFlat: - # a0 - Pointer SC_OT structure - # a1 - Pointer to next primitive - # a2 - Pointer to SMD data address - # v0 - New pointer of primitive buffer (return) - - addiu $sp, -16 - sw $s0, 0( $sp ) - sw $s1, 4( $sp ) - sw $s2, 8( $sp ) - sw $s3, 12( $sp ) - - la $v0, _sc_clip - lw $t8, 0($v0) - lw $t9, 4($v0) - - lw $t1, SMD_HEAD_PVERTS( $a2 ) - lw $t2, SMD_HEAD_PNORMS( $a2 ) - lw $t3, SMD_HEAD_PPRIMS( $a2 ) - -.sort_loop: - - nop - lw $a3, 0($t3) # Get primitive ID word - move $t4, $t3 - - beqz $a3, .exit # Check if terminator (just zero) - addiu $t4, 4 - - lhu $t5, 0( $t4 ) # Load vertices - lhu $t6, 2( $t4 ) - lhu $t7, 4( $t4 ) - sll $t5, 3 - sll $t6, 3 - sll $t7, 3 - addu $t5, $t1 - addu $t6, $t1 - addu $t7, $t1 - lwc2 C2_VXY0, 0( $t5 ) - lwc2 C2_VZ0 , 4( $t5 ) - lwc2 C2_VXY1, 0( $t6 ) - lwc2 C2_VZ1 , 4( $t6 ) - lwc2 C2_VXY2, 0( $t7 ) - lwc2 C2_VZ2 , 4( $t7 ) - - srl $v1, $a3, 24 # Get primitive size - addu $t3, $v1 # Step main pointer to next primitive - - RTPT - - cfc2 $v0, C2_FLAG # Get GTE flag value - nop - - bltz $v0, .skip_prim # Skip primitive if Z overflow - nop - - #NCLIP # Backface culling - - #mfc2 $v1, C2_MAC0 - - andi $v0, $a3, 0x3 - - #bltz $v1, .skip_prim - #nop - - beq $v0, 0x1, .prim_tri # If primitive is a triangle - nop - beq $v0, 0x2, .prim_quad # If primitive is a quad - nop - - b .skip_prim - nop - -## Triangles - -.prim_tri: # Triangle processing - - addiu $t4, 8 # Advance from indices - - #AVSZ3 # Calculate average Z - - ClipTestTri - - and $v0, $s0, $s1 # v0 & v1 - beqz $v0, .do_draw - and $v0, $s1, $s2 # v1 & v2 - beqz $v0, .do_draw - and $v0, $s2, $s0 # v2 & v0 - beqz $v0, .do_draw - nop - b .skip_prim - nop - -.do_draw: - - #srl $v0, $a3, 2 # Lighting enabled? - #andi $v0, 0x3 - #bnez $v0, .F3_light - #nop - - andi $v0, $a3, 0x20 # Textured triangle - bnez $v0, .F3_textured - nop - - andi $v0, $a3, 0x10 # Gouraud shaded - bnez $v0, .F3_gouraud - nop - - lw $v0, 0( $t4 ) # Flat color, no lighting - lui $v1, 0x2000 - or $v0, $v1 - - b .sort_F3_pri - sw $v0, POLYF3_rgbc( $a1 ) - -.F3_textured: - - lw $v0, 0( $t4 ) # Flat color, no lighting - lui $v1, 0x2400 - or $v0, $v1 - sw $v0, POLYFT3_rgbc( $a1 ) - addiu $t4, 4 - - lhu $v0, 0( $t4 ) # Load texture coordinates - lhu $v1, 2( $t4 ) - sh $v0, POLYFT3_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYFT3_uv1( $a1 ) - sh $v0, POLYFT3_uv2( $a1 ) - - lw $v0, 8( $t4 ) # Tpage + CLUT - nop - andi $v1, $v0, 0xffff - sh $v1, POLYFT3_tpage( $a1 ) - srl $v0, 16 - - b .sort_FT3_pri - sh $v0, POLYFT3_clut( $a1 ) - -.F3_gouraud: - lw $v0, 0($t4) - lw $v1, 4($t4) - .set noat - lui $at, 0x3000 - or $v0, $at - .set at - sw $v0, POLYG3_rgbc0($a1) - lw $v0, 8($t4) - sw $v1, POLYG3_rgbc1($a1) - b .sort_G3_pri - sw $v0, POLYG3_rgbc2($a1) - -#.F3_light: - - #lhu $v0, 0( $t4 ) # Load normal 0 - - #srl $v1, $a3, 2 - #andi $v1, $v1, 0x3 - - #sll $v0, 3 - #addu $v0, $t2 - #lwc2 C2_VXY0, 0( $v0 ) - #lwc2 C2_VZ0 , 4( $v0 ) - - #beq $v1, 0x2, .F3_light_smt - #nop - - #lw $v0, 4( $t4 ) - #lui $v1, 0x2000 - #or $v0, $v1 - #mtc2 $v0, C2_RGB - - #addiu $t4, 8 - #nop - - #NCCS - - #andi $v0, $a3, 0x20 # Textured triangle - #bnez $v0, .F3_light_tex - #nop - - #swc2 C2_RGB2, POLYF3_rgbc( $a1 ) - - #b .sort_F3_pri - #nop - -#.F3_light_tex: - - #lhu $v0, 0( $t4 ) # Load texture coordinates - #lhu $v1, 2( $t4 ) - #sh $v0, POLYFT3_uv0( $a1 ) - #lhu $v0, 4( $t4 ) - #sh $v1, POLYFT3_uv1( $a1 ) - #sh $v0, POLYFT3_uv2( $a1 ) - - #lw $v1, 8( $t4 ) - #nop - #andi $v0, $v1, 0xffff - #sh $v0, POLYFT3_tpage( $a1 ) - #srl $v0, $v1, 16 - #sh $v0, POLYFT3_clut( $a1 ) - - #mfc2 $v0, C2_RGB2 - #lui $v1, 0x2400 - #or $v0, $v1 - - #b .sort_FT3_pri - #sw $v0, POLYFT3_rgbc( $a1 ) - -#.F3_light_smt: - - #lhu $v0, 2( $t4 ) # Load normals 1 and 2 - #lhu $v1, 4( $t4 ) - #sll $v0, 3 - #sll $v1, 3 - #addu $v0, $t2 - #addu $v1, $t2 - #lwc2 C2_VXY1, 0( $v0 ) - #lwc2 C2_VZ1 , 4( $v0 ) - #lw $v0, 8( $t4 ) - #lwc2 C2_VXY2, 0( $v1 ) - #lwc2 C2_VZ2 , 4( $v1 ) - #lui $v1, 0x3000 # Load color - #or $v0, $v1 - #mtc2 $v0, C2_RGB - - #addiu $t4, 12 - #nop - - #NCCT - - #andi $v0, $a3, 0x20 # Textured triangle - #bnez $v0, .F3_light_tex_smt - #nop - - #swc2 C2_RGB0, POLYG3_rgbc0( $a1 ) - #swc2 C2_RGB1, POLYG3_rgbc1( $a1 ) - #swc2 C2_RGB2, POLYG3_rgbc2( $a1 ) - - #b .sort_G3_pri - #nop - -# .F3_light_tex_smt: - - # lhu $v0, 0( $t4 ) # Load texture coordinates - # lhu $v1, 2( $t4 ) - # sh $v0, POLYGT3_uv0( $a1 ) - # lhu $v0, 4( $t4 ) - # sh $v1, POLYGT3_uv1( $a1 ) - # sh $v0, POLYGT3_uv2( $a1 ) - - # lw $v1, 8( $t4 ) - # nop - # andi $v0, $v1, 0xffff - # sh $v0, POLYGT3_tpage( $a1 ) - # srl $v0, $v1, 16 - # sh $v0, POLYGT3_clut( $a1 ) - - # mfc2 $v0, C2_RGB0 - # lui $v1, 0x3400 - # or $v0, $v1 - - # swc2 C2_RGB1, POLYGT3_rgbc1( $a1 ) - # swc2 C2_RGB2, POLYGT3_rgbc2( $a1 ) - - # b .sort_GT3_pri - # sw $v0, POLYGT3_rgbc0( $a1 ) - -.sort_F3_pri: - - swc2 C2_SXY0, POLYF3_xy0($a1) - swc2 C2_SXY1, POLYF3_xy1($a1) - swc2 C2_SXY2, POLYF3_xy2($a1) - - la $v0, _smd_tpage_base - lhu $v0, 0($v0) - srl $v1, $a3, 6 # Get blend mode - andi $v1, 0x3 - sll $v1, 5 - or $v0, $v1 - lui $v1, 0xe100 - or $v0, $v1 - sw $v0, POLYF3_tpage($a1) # Store TPage - - .set noat - - lui $v1, 0x0500 - lw $v0, 0($a0) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($a0) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($a0) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYF3_len - -.sort_FT3_pri: - - swc2 C2_SXY0, POLYFT3_xy0( $a1 ) - swc2 C2_SXY1, POLYFT3_xy1( $a1 ) - swc2 C2_SXY2, POLYFT3_xy2( $a1 ) - - .set noat - - lui $v1, 0x0700 - lw $v0, 0($a0) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($a0) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($a0) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYFT3_len - -.sort_G3_pri: - - swc2 C2_SXY0, POLYG3_xy0( $a1 ) - swc2 C2_SXY1, POLYG3_xy1( $a1 ) - swc2 C2_SXY2, POLYG3_xy2( $a1 ) - - la $v0, _smd_tpage_base - lhu $v0, 0($v0) - srl $v1, $a3, 6 # Get blend mode - andi $v1, 0x3 - sll $v1, 5 - or $v0, $v1 - lui $v1, 0xe100 - or $v0, $v1 - sw $v0, POLYG3_tpage($a1) # Store TPage - - .set noat - - lui $v1, 0x0700 - lw $v0, 0($a0) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($a0) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($a0) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYG3_len - -.sort_GT3_pri: - - swc2 C2_SXY0, POLYGT3_xy0( $a1 ) - swc2 C2_SXY1, POLYGT3_xy1( $a1 ) - swc2 C2_SXY2, POLYGT3_xy2( $a1 ) - - .set noat - - lui $v1, 0x0900 - lw $v0, 0($a0) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($a0) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($a0) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYGT3_len - -## Quads - -.prim_quad: # Quad processing - - mfc2 $t6, C2_SXY0 # Retrieve first projected vertex - - lhu $t5, 6( $t4 ) # Project the last vertex - addiu $t4, 8 - sll $t5, 3 - addu $t5, $t1 - lwc2 C2_VXY0, 0( $t5 ) - lwc2 C2_VZ0 , 4( $t5 ) - - nRTPS - - cfc2 $v1, C2_FLAG # Get GTE flag value - - nop - - bltz $v1, .skip_prim - nop - - ClipTestQuad - - and $v0, $s0, $s1 # v0 & v1 - beqz $v0, .do_draw_q - and $v0, $s1, $s2 # v1 & v2 - beqz $v0, .do_draw_q - and $v0, $s2, $s3 # v2 & v3 - beqz $v0, .do_draw_q - and $v0, $s3, $s0 # v3 & v0 - beqz $v0, .do_draw_q - and $v0, $s0, $s2 # v0 & v2 - beqz $v0, .do_draw_q - and $v0, $s1, $s3 # v1 & v3 - beqz $v0, .do_draw_q - nop - b .skip_prim - nop - -.do_draw_q: - - srl $v0, $a3, 2 # Lighting enabled? - andi $v0, 0x3 - bnez $v0, .F4_light - nop - - andi $v0, $a3, 0x10 # Gouraud quad - bnez $v0, .F4_gouraud - nop - - andi $v0, $a3, 0x20 # Textured quad - bnez $v0, .F4_textured - nop - - lw $v0, 0($t4) - lui $v1, 0x2800 - or $v0, $v1 - - b .sort_F4_pri - sw $v0, POLYF4_rgbc($a1) - -.F4_textured: - - lw $v0, 0($t4) - lui $v1, 0x2c00 - or $v0, $v1 - sw $v0, POLYFT4_rgbc( $a1 ) - addiu $t4, 4 - - lhu $v0, 0($t4) # Load texture coordinates - lhu $v1, 2($t4) - sh $v0, POLYFT4_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYFT4_uv1( $a1 ) - lhu $v1, 6( $t4 ) - sh $v0, POLYFT4_uv2( $a1 ) - sh $v1, POLYFT4_uv3( $a1 ) - - lw $v1, 8( $t4 ) - nop - andi $v0, $v1, 0xffff - sh $v0, POLYFT4_tpage( $a1 ) - srl $v0, $v1, 16 - - b .sort_FT4_pri - sh $v0, POLYFT4_clut($a1) - -.F4_gouraud: - - lw $v0, 0($t4) - lw $v1, 4($t4) - .set noat - lui $at, 0x3800 - or $v0, $at - .set at - sw $v0, POLYG4_rgbc0($a1) - lw $v0, 8($t4) - sw $v1, POLYG4_rgbc1($a1) - lw $v1, 12($t4) - sw $v0, POLYG4_rgbc2($a1) - b .sort_G4_pri - sw $v1, POLYG4_rgbc3($a1) - - -.F4_light: - - lhu $v0, 0( $t4 ) # Load normal 0 - - srl $v1, $a3, 2 - andi $v1, $v1, 0x3 - - sll $v0, 3 - addu $v0, $t2 - lwc2 C2_VXY0, 0( $v0 ) - lwc2 C2_VZ0 , 4( $v0 ) - - beq $v1, 0x2, .F4_light_smt - nop - - lw $v0, 4( $t4 ) - lui $v1, 0x2800 - or $v0, $v1 - mtc2 $v0, C2_RGB - - addiu $t4, 8 - nop - - NCCS - - andi $v0, $a3, 0x20 # Textured triangle - bnez $v0, .F4_light_tex - nop - - swc2 C2_RGB2, POLYF4_rgbc( $a1 ) - - b .sort_F4_pri - nop - -.F4_light_tex: - - lhu $v0, 0( $t4 ) # Load texture coordinates - lhu $v1, 2( $t4 ) - sh $v0, POLYFT4_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYFT4_uv1( $a1 ) - lhu $v1, 6( $t4 ) - sh $v0, POLYFT4_uv2( $a1 ) - sh $v1, POLYFT4_uv3( $a1 ) - - lw $v1, 8( $t4 ) - nop - andi $v0, $v1, 0xffff - sh $v0, POLYFT4_tpage( $a1 ) - srl $v0, $v1, 16 - sh $v0, POLYFT4_clut( $a1 ) - - mfc2 $v0, C2_RGB2 - lui $v1, 0x2c00 - or $v0, $v1 - - b .sort_FT4_pri - sw $v0, POLYFT4_rgbc( $a1 ) - -.F4_light_smt: - - lhu $v0, 2( $t4 ) # Load normals 1 and 2 - lhu $v1, 4( $t4 ) - sll $v0, 3 - sll $v1, 3 - addu $v0, $t2 - addu $v1, $t2 - lwc2 C2_VXY1, 0( $v0 ) - lwc2 C2_VZ1 , 4( $v0 ) - lwc2 C2_VXY2, 0( $v1 ) - lwc2 C2_VZ2 , 4( $v1 ) - - lw $v0, 8( $t4 ) - lui $v1, 0x3800 # Load color - or $v0, $v1 - mtc2 $v0, C2_RGB - - nNCCT - - lhu $v0, 6( $t4 ) # Load normal 3 - - addiu $t4, 12 - - sll $v0, 3 - addu $v0, $t2 - lwc2 C2_VXY0, 0( $v0 ) - lwc2 C2_VZ0 , 4( $v0 ) - - andi $v0, $a3, 0x20 # Textured triangle - bnez $v0, .F4_light_tex_smt - nop - - swc2 C2_RGB0, POLYG4_rgbc0( $a1 ) - swc2 C2_RGB1, POLYG4_rgbc1( $a1 ) - swc2 C2_RGB2, POLYG4_rgbc2( $a1 ) - - nNCCS - - swc2 C2_RGB2, POLYG4_rgbc3( $a1 ) - - b .sort_G4_pri - nop - -.F4_light_tex_smt: - - mfc2 $v0, C2_RGB0 - lui $v1, 0x3400 - or $v0, $v1 - sw $v0, POLYGT4_rgbc0( $a1 ) - swc2 C2_RGB1, POLYGT4_rgbc1( $a1 ) - swc2 C2_RGB2, POLYGT4_rgbc2( $a1 ) - - NCCS - - lhu $v0, 0( $t4 ) # Load texture coordinates - lhu $v1, 2( $t4 ) - sh $v0, POLYGT4_uv0( $a1 ) - lhu $v0, 4( $t4 ) - sh $v1, POLYGT4_uv1( $a1 ) - lhu $v1, 6( $t4 ) - sh $v0, POLYGT4_uv2( $a1 ) - sh $v1, POLYGT4_uv3( $a1 ) - - lw $v1, 8( $t4 ) - swc2 C2_RGB2, POLYGT4_rgbc3( $a1 ) - - andi $v0, $v1, 0xffff - sh $v0, POLYGT4_tpage( $a1 ) - srl $v0, $v1, 16 - - b .sort_GT4_pri - sh $v0, POLYGT4_clut( $a1 ) - -.sort_F4_pri: - - sw $t6, POLYF4_xy0($a1) - swc2 C2_SXY0, POLYF4_xy1($a1) - swc2 C2_SXY1, POLYF4_xy2($a1) - swc2 C2_SXY2, POLYF4_xy3($a1) - - la $v0, _smd_tpage_base - lhu $v0, 0($v0) - srl $v1, $a3, 6 # Get blend mode - andi $v1, 0x3 - sll $v1, 5 - or $v0, $v1 - lui $v1, 0xe100 - or $v0, $v1 - sw $v0, POLYF4_tpage($a1) # Store TPage - - .set noat - - lui $v1, 0x0600 - lw $v0, 0($a0) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($a0) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($a0) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYF4_len - -.sort_FT4_pri: - - sw $t6, POLYFT4_xy0($a1) - swc2 C2_SXY0, POLYFT4_xy1($a1) - swc2 C2_SXY1, POLYFT4_xy2($a1) - swc2 C2_SXY2, POLYFT4_xy3($a1) - - .set noat - - lui $v1, 0x0900 - lw $v0, 0($a0) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($a0) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($a0) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYFT4_len - -.sort_G4_pri: - - sw $t6, POLYG4_xy0($a1) - swc2 C2_SXY0, POLYG4_xy1($a1) - swc2 C2_SXY1, POLYG4_xy2($a1) - swc2 C2_SXY2, POLYG4_xy3($a1) - - la $v0, _smd_tpage_base - lhu $v0, 0($v0) - srl $v1, $a3, 6 # Get blend mode - andi $v1, 0x3 - sll $v1, 5 - or $v0, $v1 - lui $v1, 0xe100 - or $v0, $v1 - sw $v0, POLYG4_tpage($a1) # Store TPage - - .set noat - - lui $v1, 0x0900 - lw $v0, 0($a0) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($a0) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($a0) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYG4_len - -.sort_GT4_pri: - - sw $t6, POLYGT4_xy0($a1) - swc2 C2_SXY0, POLYGT4_xy1($a1) - swc2 C2_SXY1, POLYGT4_xy2($a1) - swc2 C2_SXY2, POLYGT4_xy3($a1) - - .set noat - - lui $v1, 0x0c00 - lw $v0, 0($a0) - lui $at, 0xff00 - and $v1, $at - lui $at, 0x00ff - or $at, 0xffff - and $v0, $at - or $v1, $v0 - sw $v1, 0($a1) - lw $v0, 0($a0) - and $a1, $at - lui $at, 0xff00 - and $v0, $at - or $v0, $a1 - sw $v0, 0($a0) - - .set at - - lui $v0, 0x8000 - or $a1, $v0 - - b .sort_loop - addiu $a1, POLYGT4_len - -.skip_prim: - - b .sort_loop - nop - -.exit: - - lw $s0, 0( $sp ) - lw $s1, 4( $sp ) - lw $s2, 8( $sp ) - lw $s3, 12( $sp ) - addiu $sp, 16 - jr $ra - move $v0, $a1 - \ No newline at end of file diff --git a/examples/n00bdemo/smd_s.h b/examples/n00bdemo/smd_s.h deleted file mode 100644 index 4dca4dd..0000000 --- a/examples/n00bdemo/smd_s.h +++ /dev/null @@ -1,336 +0,0 @@ -.set OT_ADDR, 0 -.set OT_LEN, 4 -.set OT_ZDIV, 8 -.set OT_ZOFF, 10 - -.set SMD_HEAD_ID, 0 -.set SMD_HEAD_FLAG, 4 -.set SMD_HEAD_NVERTS, 6 -.set SMD_HEAD_NNORMS, 8 -.set SMD_HEAD_NPRIMS, 10 -.set SMD_HEAD_PVERTS, 12 -.set SMD_HEAD_PNORMS, 16 -.set SMD_HEAD_PPRIMS, 20 -.set SMD_HEAD_SIZE, 24 - -.set POLYF3_tag, 0 -.set POLYF3_tpage, 4 -.set POLYF3_rgbc, 8 -.set POLYF3_xy0, 12 -.set POLYF3_xy1, 16 -.set POLYF3_xy2, 20 -.set POLYF3_len, 24 - -.set POLYFT3_tag, 0 -.set POLYFT3_rgbc, 4 -.set POLYFT3_xy0, 8 -.set POLYFT3_uv0, 12 -.set POLYFT3_clut, 14 -.set POLYFT3_xy1, 16 -.set POLYFT3_uv1, 20 -.set POLYFT3_tpage, 22 -.set POLYFT3_xy2, 24 -.set POLYFT3_uv2, 28 -.set POLYFT3_pad, 30 -.set POLYFT3_len, 32 - -.set POLYG3_tag, 0 -.set POLYG3_tpage, 4 -.set POLYG3_rgbc0, 8 -.set POLYG3_xy0, 12 -.set POLYG3_rgbc1, 16 -.set POLYG3_xy1, 20 -.set POLYG3_rgbc2, 24 -.set POLYG3_xy2, 28 -.set POLYG3_len, 32 - -.set POLYGT3_tag, 0 -.set POLYGT3_rgbc0, 4 -.set POLYGT3_xy0, 8 -.set POLYGT3_uv0, 12 -.set POLYGT3_clut, 14 -.set POLYGT3_rgbc1, 16 -.set POLYGT3_xy1, 20 -.set POLYGT3_uv1, 24 -.set POLYGT3_tpage, 26 -.set POLYGT3_rgbc2, 28 -.set POLYGT3_xy2, 32 -.set POLYGT3_uv2, 36 -.set POLYGT3_pad, 38 -.set POLYGT3_len, 40 - -.set POLYF4_tag, 0 -.set POLYF4_tpage, 4 -.set POLYF4_rgbc, 8 -.set POLYF4_xy0, 12 -.set POLYF4_xy1, 16 -.set POLYF4_xy2, 20 -.set POLYF4_xy3, 24 -.set POLYF4_len, 28 - -.set POLYFT4_tag, 0 -.set POLYFT4_rgbc, 4 -.set POLYFT4_xy0, 8 -.set POLYFT4_uv0, 12 -.set POLYFT4_clut, 14 -.set POLYFT4_xy1, 16 -.set POLYFT4_uv1, 20 -.set POLYFT4_tpage, 22 -.set POLYFT4_xy2, 24 -.set POLYFT4_uv2, 28 -.set POLYFT4_pad0, 30 -.set POLYFT4_xy3, 32 -.set POLYFT4_uv3, 36 -.set POLYFT4_pad1, 38 -.set POLYFT4_len, 40 - -.set POLYG4_tag, 0 -.set POLYG4_tpage, 4 -.set POLYG4_rgbc0, 8 -.set POLYG4_xy0, 12 -.set POLYG4_rgbc1, 16 -.set POLYG4_xy1, 20 -.set POLYG4_rgbc2, 24 -.set POLYG4_xy2, 28 -.set POLYG4_rgbc3, 32 -.set POLYG4_xy3, 36 -.set POLYG4_len, 40 - -.set POLYGT4_tag, 0 -.set POLYGT4_rgbc0, 4 -.set POLYGT4_xy0, 8 -.set POLYGT4_uv0, 12 -.set POLYGT4_clut, 14 -.set POLYGT4_rgbc1, 16 -.set POLYGT4_xy1, 20 -.set POLYGT4_uv1, 24 -.set POLYGT4_tpage, 26 -.set POLYGT4_rgbc2, 28 -.set POLYGT4_xy2, 32 -.set POLYGT4_uv2, 36 -.set POLYGT4_pad0, 38 -.set POLYGT4_rgbc3, 40 -.set POLYGT4_xy3, 44 -.set POLYGT4_uv3, 48 -.set POLYGT4_pad1, 50 -.set POLYGT4_len, 52 - -.set CLIP_LEFT, 1 -.set CLIP_RIGHT, 2 -.set CLIP_TOP, 4 -.set CLIP_BOTTOM, 8 - - -# Clip routine macros, based on Cohen-Sutherland line clipping algorithm -# but only with the off-screen dectection logic extended for polygons - -.macro ClipTestTri - - # X0 clip test - mfc2 $t7, C2_SXY0 - sll $v1, $t8, 16 - sra $v1, 16 - sll $v0, $t7, 16 - sra $v0, 16 - bge $v0, $v1, .no_clip_l_x0 - move $s0, $0 - ori $s0, CLIP_LEFT -.no_clip_l_x0: - sll $v1, $t9, 16 - sra $v1, 16 - ble $v0, $v1, .no_clip_r_x0 - nop - ori $s0, CLIP_RIGHT -.no_clip_r_x0: - # Y0 clip test - sra $v0, $t7, 16 - sra $v1, $t8, 16 - bge $v0, $v1, .no_clip_t_y0 - nop - ori $s0, CLIP_TOP -.no_clip_t_y0: - sra $v1, $t9, 16 - ble $v0, $v1, .no_clip_b_y0 - nop - ori $s0, CLIP_BOTTOM -.no_clip_b_y0: - - # X1 clip test - mfc2 $t7, C2_SXY1 - sll $v1, $t8, 16 - sra $v1, 16 - sll $v0, $t7, 16 - sra $v0, 16 - bge $v0, $v1, .no_clip_l_x1 - move $s1, $0 - ori $s1, CLIP_LEFT -.no_clip_l_x1: - sll $v1, $t9, 16 - sra $v1, 16 - ble $v0, $v1, .no_clip_r_x1 - nop - ori $s1, CLIP_RIGHT -.no_clip_r_x1: - # Y1 clip test - sra $v0, $t7, 16 - sra $v1, $t8, 16 - bge $v0, $v1, .no_clip_t_y1 - nop - ori $s1, CLIP_TOP -.no_clip_t_y1: - sra $v1, $t9, 16 - ble $v0, $v1, .no_clip_b_y1 - nop - ori $s1, CLIP_BOTTOM -.no_clip_b_y1: - - # X2 clip test - mfc2 $t7, C2_SXY2 - sll $v1, $t8, 16 - sra $v1, 16 - sll $v0, $t7, 16 - sra $v0, 16 - bge $v0, $v1, .no_clip_l_x2 - move $s2, $0 - ori $s2, CLIP_LEFT -.no_clip_l_x2: - sll $v1, $t9, 16 - sra $v1, 16 - ble $v0, $v1, .no_clip_r_x2 - nop - ori $s2, CLIP_RIGHT -.no_clip_r_x2: - # Y2 clip test - sra $v0, $t7, 16 - sra $v1, $t8, 16 - bge $v0, $v1, .no_clip_t_y2 - nop - ori $s2, CLIP_TOP -.no_clip_t_y2: - sra $v1, $t9, 16 - ble $v0, $v1, .no_clip_b_y2 - nop - ori $s2, CLIP_BOTTOM -.no_clip_b_y2: - -.endm - - -.macro ClipTestQuad - - # X0 clip test - sll $v0, $t6, 16 - sra $v0, 16 - sll $v1, $t8, 16 - sra $v1, 16 - bge $v0, $v1, .no_clip_l_x0_q - move $s0, $0 - ori $s0, CLIP_LEFT -.no_clip_l_x0_q: - sll $v1, $t9, 16 - sra $v1, 16 - ble $v0, $v1, .no_clip_r_x0_q - nop - ori $s0, CLIP_RIGHT -.no_clip_r_x0_q: - # Y0 clip test - sra $v0, $t6, 16 - sra $v1, $t8, 16 - bge $v0, $v1, .no_clip_t_y0_q - nop - ori $s0, CLIP_TOP -.no_clip_t_y0_q: - sra $v1, $t9, 16 - ble $v0, $v1, .no_clip_b_y0_q - nop - ori $s0, CLIP_BOTTOM -.no_clip_b_y0_q: - - # X1 clip test - mfc2 $t7, C2_SXY0 - sll $v1, $t8, 16 - sra $v1, 16 - sll $v0, $t7, 16 - sra $v0, 16 - bge $v0, $v1, .no_clip_l_x1_q - move $s1, $0 - ori $s1, CLIP_LEFT -.no_clip_l_x1_q: - sll $v1, $t9, 16 - sra $v1, 16 - ble $v0, $v1, .no_clip_r_x1_q - nop - ori $s1, CLIP_RIGHT -.no_clip_r_x1_q: - # Y1 clip test - sra $v0, $t7, 16 - sra $v1, $t8, 16 - bge $v0, $v1, .no_clip_t_y1_q - nop - ori $s1, CLIP_TOP -.no_clip_t_y1_q: - sra $v1, $t9, 16 - ble $v0, $v1, .no_clip_b_y1_q - nop - ori $s1, CLIP_BOTTOM -.no_clip_b_y1_q: - - # X2 clip test - mfc2 $t7, C2_SXY1 - sll $v1, $t8, 16 - sra $v1, 16 - sll $v0, $t7, 16 - sra $v0, 16 - bge $v0, $v1, .no_clip_l_x2_q - move $s2, $0 - ori $s2, CLIP_LEFT -.no_clip_l_x2_q: - sll $v1, $t9, 16 - sra $v1, 16 - ble $v0, $v1, .no_clip_r_x2_q - nop - ori $s2, CLIP_RIGHT -.no_clip_r_x2_q: - # Y2 clip test - sra $v0, $t7, 16 - sra $v1, $t8, 16 - bge $v0, $v1, .no_clip_t_y2_q - nop - ori $s2, CLIP_TOP -.no_clip_t_y2_q: - sra $v1, $t9, 16 - ble $v0, $v1, .no_clip_b_y2_q - nop - ori $s2, CLIP_BOTTOM -.no_clip_b_y2_q: - - # X3 clip test - mfc2 $t7, C2_SXY2 - sll $v1, $t8, 16 - sra $v1, 16 - sll $v0, $t7, 16 - sra $v0, 16 - bge $v0, $v1, .no_clip_l_x3_q - move $s3, $0 - ori $s3, CLIP_LEFT -.no_clip_l_x3_q: - sll $v1, $t9, 16 - sra $v1, 16 - ble $v0, $v1, .no_clip_r_x3_q - nop - ori $s3, CLIP_RIGHT -.no_clip_r_x3_q: - # Y4 clip test - sra $v0, $t7, 16 - sra $v1, $t8, 16 - bge $v0, $v1, .no_clip_t_y3_q - nop - ori $s3, CLIP_TOP -.no_clip_t_y3_q: - sra $v1, $t9, 16 - ble $v0, $v1, .no_clip_b_y3_q - nop - ori $s3, CLIP_BOTTOM -.no_clip_b_y3_q: - -.endm diff --git a/examples/n00bdemo/smdparser.s b/examples/n00bdemo/smdparser.s deleted file mode 100644 index 379690f..0000000 --- a/examples/n00bdemo/smdparser.s +++ /dev/null @@ -1,129 +0,0 @@ -.set noreorder - -.include "smd_s.h" - -.set SMD_PRI_ID, 0 -.set SMD_PRI_v0, 4 -.set SMD_PRI_v1, 6 -.set SMD_PRI_v2, 8 -.set SMD_PRI_v3, 10 -.set SMD_PRI_n0, 12 -.set SMD_PRI_n1, 14 -.set SMD_PRI_n2, 16 -.set SMD_PRI_n3, 18 -.set SMD_PRI_rgbc0, 20 -.set SMD_PRI_rgbc1, 24 -.set SMD_PRI_rgbc2, 28 -.set SMD_PRI_rgbc3, 32 -.set SMD_PRI_tuv0, 36 -.set SMD_PRI_tuv1, 38 -.set SMD_PRI_tuv2, 40 -.set SMD_PRI_tuv3, 42 -.set SMD_PRI_tpage, 44 -.set SMD_PRI_clut, 46 - -.section .text - - -.comm _smd_parse_addr, 4, 4 - - -.global OpenSMD -.type OpenSMD, @function -OpenSMD: - lw $v0, SMD_HEAD_ID($a0) - li $v1, 0x01444d53 - - bne $v0, $v1, .not_smd - nop - - lw $v0, SMD_HEAD_PPRIMS($a0) - la $v1, _smd_parse_addr - sw $v0, 0($v1) - - jr $ra - lhu $v0, SMD_HEAD_NPRIMS($a0) - -.not_smd: - jr $ra - move $v0, $0 - - -.global ReadSMD -.type ReadSMD, @function -ReadSMD: - - la $v0, _smd_parse_addr - lw $v0, 0($v0) - nop - - lw $a2, 0($v0) # Load primitive ID - addiu $a1, $v0, 4 - - sw $a2, SMD_PRI_ID($a0) - - beqz $a2, $end_prim - nop - - srl $v1, $a2, 24 # Get primitive size - addu $v0, $v1 - la $v1, _smd_parse_addr - sw $v0, 0($v1) - - lw $v0, 0($a1) # Copy vertex coords - lw $v1, 4($a1) - sw $v0, SMD_PRI_v0($a0) - sw $v1, SMD_PRI_v2($a0) - addiu $a1, 8 - - srl $v0, $a2, 2 # Lighting enabled? - andi $v0, 0x3 - bnez $v0, $light - nop - - b $no_light - nop - -$light: - srl $v1, $a2, 2 - lw $v0, 0($a1) # Copy vertex coords - andi $v1, 0x3 - sw $v0, SMD_PRI_n0($a0) - - bne $v1, 0x2, $light_flat - addiu $a1, 4 - - lw $v1, 0($a1) - addiu $a1, 4 - sw $v1, SMD_PRI_n2($a0) - -$light_flat: -$no_light: - - lw $v0, 0($a1) - nop - sw $v0, SMD_PRI_rgbc0($a0) - addiu $a1, 4 - - srl $v0, $a2, 5 - andi $v0, 0x1 - beqz $v0, $not_textured - nop - - lw $v0, 0($a1) - lw $v1, 4($a1) - sw $v0, SMD_PRI_tuv0($a0) - lw $v0, 8($a1) - sw $v1, SMD_PRI_tuv2($a0) - sw $v0, SMD_PRI_tpage($a0) - -$not_textured: - - jr $ra - move $v0, $a0 - -$end_prim: - - jr $ra - move $v0, $0 - \ No newline at end of file diff --git a/examples/render2tex/blendpattern-16c.png b/examples/render2tex/blendpattern-16c.png deleted file mode 100644 index 74ac945..0000000 Binary files a/examples/render2tex/blendpattern-16c.png and /dev/null differ diff --git a/examples/render2tex/blendpattern-16c.tim b/examples/render2tex/blendpattern-16c.tim deleted file mode 100644 index 2fff580..0000000 Binary files a/examples/render2tex/blendpattern-16c.tim and /dev/null differ diff --git a/examples/render2tex/blendpattern.png b/examples/render2tex/blendpattern.png deleted file mode 100644 index 49af62c..0000000 Binary files a/examples/render2tex/blendpattern.png and /dev/null differ diff --git a/examples/render2tex/main.c b/examples/render2tex/main.c deleted file mode 100644 index 6ae450a..0000000 --- a/examples/render2tex/main.c +++ /dev/null @@ -1,649 +0,0 @@ -/* - * LibPSn00b Example Programs - * - * Off-screen Render to Texture Example - * 2019 Meido-Tek Productions / PSn00bSDK Project - * - * Demonstrates quick render to texture for multi-texture style effects, - * view screens and more. This example also shows how to use multiple - * ordering tables and chaining them together so it can all be rendered - * with a single DrawOTag() call. - * - * Example by Lameguy64 - * - * Changelog: - * - * Oct 26, 2019 - Initial version. - * - */ - -#include -#include -#include -#include - - -/* OT and Packet Buffer sizes */ -#define OT_LEN 256 -#define PACKET_LEN 1024 - - -/* Screen resolution */ -/* (note: display/draw code is hardcoded for double buffer) */ -#define SCREEN_XRES 320 -#define SCREEN_YRES 240 - - -/* Screen center position */ -#define CENTERX SCREEN_XRES>>1 -#define CENTERY SCREEN_YRES>>1 - - -/* Double buffer structure */ -typedef struct DB -{ - DISPENV disp; /* Display environment */ - DRAWENV draw; /* Drawing environment */ - int ot[OT_LEN]; /* Main ordering table */ - int sub_ot[2][4]; /* Second ordering table for r2t stuff */ - char p[PACKET_LEN]; /* Packet buffer */ -} DB; - - -/* Double buffer variables */ -DB db[2]; -int db_active = 0; -char *db_nextpri; - - -/* For easier handling of vertex indices */ -typedef struct { - short v0,v1,v2,v3; -} INDEX; - -/* Cube vertices */ -SVECTOR cube_verts[] = { - { -100, -100, -100, 0 }, - { 100, -100, -100, 0 }, - { -100, 100, -100, 0 }, - { 100, 100, -100, 0 }, - { 100, -100, 100, 0 }, - { -100, -100, 100, 0 }, - { 100, 100, 100, 0 }, - { -100, 100, 100, 0 } -}; - -/* Cube face normals */ -SVECTOR cube_norms[] = { - { 0, 0, -ONE, 0 }, - { 0, -ONE, 0, 0 }, - { 0, 0, ONE, 0 }, - { 0, ONE, 0, 0 }, - { ONE, 0, 0, 0 }, - { -ONE, 0, 0, 0 } -}; - -/* Cube vertex indices */ -INDEX cube_indices[] = { - { 0, 1, 2, 3 }, - { 5, 4, 0, 1 }, - { 4, 5, 6, 7 }, - { 6, 7, 3, 2 }, - { 3, 1, 6, 4 }, - { 0, 2, 5, 7 } -}; - -/* Number of cube faces */ -#define CUBE_FACES 6 - -/* Light color matrix */ -MATRIX color_mtx = { - ONE, 0, 0, /* Red */ - ONE, 0, 0, /* Green */ - ONE, 0, 0 /* Blue */ -}; - -/* Light matrix */ -MATRIX light_mtx = { - /* X, Y, Z */ - -2048 , -2048 , -2048, - 0 , 0 , 0, - 0 , 0 , 0 -}; - - -/* Reference texture data */ -extern int tim_blendpattern[]; - - -/* TPage and CLUT values */ -unsigned short rendertex_tpage; /* For the render to texture cube */ -unsigned short bpattern_tpage; /* For the scrolling blending pattern */ -unsigned short bpattern_clut; - - -/* Function declarations */ -void init(); -void display(); - -/* This function sorts a cube that is drawn - * to an offscreen area specified by *area */ -void sort_cube(int *ot, RECT *area); -void sort_multitex(int *ot, RECT *area, int count); - -/* Main function */ -int main() { - - int i,p,xy_temp; - int count = 0; - - SVECTOR rot = { 0 }; /* Rotation vector for Rotmatrix */ - VECTOR pos = { 0, 0, 400 }; /* Translation vector for TransMatrix */ - MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ - - VECTOR spos = { 0, 0, 250 }; - SVECTOR srot = { 0 }; - - RECT texarea,area,dtexarea; - RECT cubearea; - - POLY_FT4 *pol4; /* Flat shaded quad primitive pointer */ - - - /* Init graphics and GTE */ - init(); - - setRECT(&area, 704, 0, 64, 64); - setRECT(&cubearea, 704, 64, 64, 64); - - setRECT(&texarea, 0, 0, 64>>3, 64>>3); - setRECT(&dtexarea, 0, 0, 0, 0); - - rendertex_tpage = getTPage(2, 0, area.x, area.y); - - /* Main loop */ - while( 1 ) { - - /* Sort multi-texture stuff */ - sort_multitex(db[db_active].ot+(OT_LEN-1), &area, count); - - /* Matrix stuff for render to texture cube */ - RotMatrix( &srot, &mtx ); - TransMatrix( &mtx, &spos ); - - MulMatrix0( &light_mtx, &mtx, &lmtx ); - - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - gte_SetLightMatrix( &lmtx ); - - /* Reduce FOV to fit in area and sort cube */ - gte_SetGeomScreen(32); - - sort_cube(db[db_active].ot+(OT_LEN-1), &cubearea); - - gte_SetGeomScreen(CENTERX); - - - /* Set rotation and translation to the matrix */ - RotMatrix( &rot, &mtx ); - TransMatrix( &mtx, &pos ); - - /* Multiply light matrix by rotation matrix so light source */ - /* won't appear relative to the model's rotation */ - MulMatrix0( &light_mtx, &mtx, &lmtx ); - - /* Set rotation and translation matrix */ - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - /* Set light matrix */ - gte_SetLightMatrix( &lmtx ); - - /* Make the cube SPEEN */ - rot.vx += 4; - rot.vz += 4; - - srot.vx += 8; - srot.vy += 8; - srot.vz -= 8; - - /* Draw the cube */ - pol4 = (POLY_FT4*)db_nextpri; - - for( i=0; i>2) > OT_LEN ) - continue; - - /* Initialize a quad primitive */ - setPolyFT4( pol4 ); - - /* Set the projected vertices to the primitive */ - gte_stsxy0( &pol4->x0 ); - gte_stsxy1( &pol4->x1 ); - gte_stsxy2( &pol4->x2 ); - - /* Compute the last vertex and set the result */ - gte_ldv0( &cube_verts[cube_indices[i].v3] ); - gte_rtps(); - gte_stsxy( &pol4->x3 ); - - /* Load primitive color even though gte_ncs() doesn't use it. */ - /* This is so the GTE will output a color result with the */ - /* correct primitive code. */ - gte_ldrgb( &pol4->r0 ); - - /* Load the face normal */ - gte_ldv0( &cube_norms[i] ); - - /* Normal Color Single */ - gte_ncs(); - - /* Store result to the primitive */ - gte_strgb( &pol4->r0 ); - - // Map to render to texture texture - pol4->tpage = rendertex_tpage; - if( (i&0x1) == 0 ) - setUVWH(pol4, 0, 0, 63, 63); - else - setUVWH(pol4, 0, 64, 63, 63); - - - /* Sort primitive to the ordering table */ - addPrim( db[db_active].ot+(p>>2), pol4 ); - - /* Advance to make another primitive */ - pol4++; - - } - - /* Update nextpri variable */ - /* (IMPORTANT if you plan to sort more primitives after this) */ - db_nextpri = (char*)pol4; - - /* Swap buffers and draw the primitives */ - display(); - - count++; - - } - - return 0; - -} - -void init() { - - TIM_IMAGE tim; - - /* Reset the GPU, also installs a VSync event handler */ - ResetGraph( 0 ); - - /* Set display and draw environment areas */ - /* (display and draw areas must be separate, otherwise hello flicker) */ - SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - - /* Enable draw area clear and dither processing */ - setRGB0( &db[0].draw, 63, 0, 127 ); - db[0].draw.isbg = 1; - db[0].draw.dtd = 1; - - - /* Define the second set of display/draw environments */ - SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); - - setRGB0( &db[1].draw, 63, 0, 127 ); - db[1].draw.isbg = 1; - db[1].draw.dtd = 1; - - - /* Apply the drawing environment of the first double buffer */ - PutDrawEnv( &db[0].draw ); - - - /* Clear both ordering tables to make sure they are clean at the start */ - ClearOTagR( db[0].ot, OT_LEN ); - ClearOTagR( db[1].ot, OT_LEN ); - ClearOTagR( db[0].sub_ot[0], 4 ); - ClearOTagR( db[0].sub_ot[1], 4 ); - ClearOTagR( db[1].sub_ot[0], 4 ); - ClearOTagR( db[1].sub_ot[1], 4 ); - - /* Set primitive pointer address */ - db_nextpri = db[0].p; - - /* Initialize the GTE */ - InitGeom(); - - /* Set GTE offset (recommended method of centering) */ - gte_SetGeomOffset( CENTERX, CENTERY ); - - /* Set screen depth (basically FOV control, W/2 works best) */ - gte_SetGeomScreen( CENTERX ); - - /* Set light ambient color and light color matrix */ - gte_SetBackColor( 63, 63, 63 ); - gte_SetColorMatrix( &color_mtx ); - - GetTimInfo(tim_blendpattern, &tim); - if( tim.mode & 0x8 ) - { - LoadImage( tim.crect, tim.caddr ); /* Upload CLUT if present */ - } - LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */ - - bpattern_tpage = getTPage(0, 1, tim.prect->x, tim.prect->y); - bpattern_clut = getClut(tim.crect->x, tim.crect->y); - -} - -void display() { - - /* Wait for GPU to finish drawing and vertical retrace */ - DrawSync( 0 ); - VSync( 0 ); - - /* Swap buffers */ - db_active ^= 1; - db_nextpri = db[db_active].p; - - /* Clear the OT of the next frame */ - ClearOTagR( db[db_active].ot, OT_LEN ); - ClearOTagR( db[db_active].sub_ot[0], 4 ); - ClearOTagR( db[db_active].sub_ot[1], 4 ); - - /* Apply display/drawing environments */ - PutDrawEnv( &db[db_active].draw ); - PutDispEnv( &db[db_active].disp ); - - /* Enable display */ - SetDispMask( 1 ); - - /* Start drawing the OT of the last buffer */ - DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); - -} - -void sort_multitex(int *ot, RECT *area, int count) -{ - DR_TPAGE *ptpage; - FILL *pfill; - DR_AREA *parea; - DR_TWIN *ptwin; - DR_OFFSET *poffs; - - SPRT *psprt; - - /* Texture window constraint */ - /* (coordinates specified in units of 8 pixels) */ - RECT texwindow = { 0, 0, 64>>3, 64>>3 }; - - /* Sort the sub OT to the specified OT level */ - addPrims( - ot, /* Target OT */ - db[db_active].sub_ot[0]+3, /* Start of OT to sort */ - db[db_active].sub_ot[0]); /* End of OT to sort */ - - - /* Sort a FILL primitive to clear the off-screen area */ - pfill = (FILL*)db_nextpri; - setFill(pfill); - setXY0(pfill, area->x, area->y); - setWH(pfill, 64, 64); - setRGB0(pfill, 0, 0, 0); - addPrim(db[db_active].sub_ot[0]+3, pfill); - db_nextpri += sizeof(FILL); - - - /* Sort draw area primitives to set the drawing target */ - parea = (DR_AREA*)db_nextpri; - - setDrawArea(parea, area); /* Sets to off-screen area */ - addPrim(db[db_active].sub_ot[0]+3, parea); - parea++; - - setDrawArea(parea, /* Reverts to draw area */ - &db[1-db_active].draw.clip); - addPrim(db[db_active].sub_ot[0]+1, parea); - parea++; - db_nextpri = (char*)parea; - - - /* Sort offset primitives to set the drawing offset to the target */ - poffs = (DR_OFFSET*)db_nextpri; - - setDrawOffset(poffs, area->x, area->y); /* Sets to off-screen area */ - addPrim(db[db_active].sub_ot[0]+3, poffs); - poffs++; - - setDrawOffset(poffs, /* Reverts to draw area */ - db[1-db_active].draw.clip.x, - db[1-db_active].draw.clip.y); - addPrim(db[db_active].sub_ot[0]+1, poffs); - poffs++; - db_nextpri = (char*)poffs; - - - /* This sets the active texture page for the SPRT primitives */ - ptpage = (DR_TPAGE*)db_nextpri; - setDrawTPage(ptpage, 1, 0, bpattern_tpage); - addPrim(db[db_active].sub_ot[0]+3, ptpage); - ptpage++; - db_nextpri = (char*)ptpage; - - - /* Sort a DR_TWIN primitive to wrap texture coordinates to 64x64 */ - ptwin = (DR_TWIN*)db_nextpri; - - setTexWindow(ptwin, &texwindow); /* Set window constraint */ - addPrim(db[db_active].sub_ot[0]+3, ptwin); - ptwin++; - - texwindow.w = 0; /* Clear window constraint */ - texwindow.h = 0; - setTexWindow(ptwin, &texwindow); - addPrim(db[db_active].sub_ot[0]+1, ptwin); - ptwin++; - db_nextpri = (char*)ptwin; - - - /* Sort blending and scrolling sprites layering over one another */ - psprt = (SPRT*)db_nextpri; - - /* Sort pattern in green scrolling up-left */ - setSprt(psprt); - setSemiTrans(psprt, 1); - setXY0(psprt, 0, 0); - setWH(psprt, 64, 64); - setUV0(psprt, (count>>1)&0x3F, count&0x3F); - setRGB0(psprt, 0, 91, 0); - psprt->clut = bpattern_clut; - addPrim(db[db_active].sub_ot[0]+1, psprt); - psprt++; - - /* Sort pattern in blue scrolling up-right*/ - setSprt(psprt); - setSemiTrans(psprt, 1); - setXY0(psprt, 0, 0); - setWH(psprt, 64, 64); - setUV0(psprt, (-count>>1)&0x3F, (count>>1)&0x3F); - setRGB0(psprt, 0, 0, 91); - psprt->clut = bpattern_clut; - addPrim(db[db_active].sub_ot[0]+1, psprt); - psprt++; - - /* Sort pattern in red scrolling down-right */ - setSprt(psprt); - setSemiTrans(psprt, 1); - setXY0(psprt, 0, 0); - setWH(psprt, 64, 64); - setUV0(psprt, (-count>>1)&0x3F, (-count>>1)&0x3F); - setRGB0(psprt, 91, 0, 0); - psprt->clut = bpattern_clut; - addPrim(db[db_active].sub_ot[0]+1, psprt); - psprt++; - - /* Sort pattern in grey scrolling up-left */ - setSprt(psprt); - setXY0(psprt, 0, 0); - setWH(psprt, 64, 64); - setUV0(psprt, count&0x3F, (count>>1)&0x3F); - setRGB0(psprt, 64, 64, 64); - psprt->clut = bpattern_clut; - addPrim(db[db_active].sub_ot[0]+1, psprt); - psprt++; - - db_nextpri = (char*)psprt; - -} - -void sort_cube(int *ot, RECT *area) -{ - int i,p; - POLY_FT4* pol4; - FILL* pfill; - DR_AREA* parea; - DR_OFFSET* poffs; - - addPrims( - ot, - db[db_active].sub_ot[1]+3, - db[db_active].sub_ot[1]); - - pfill = (FILL*)db_nextpri; - setFill(pfill); - setXY0(pfill, area->x, area->y); - setWH(pfill, 64, 64); - setRGB0(pfill, 128, 91, 0); - addPrim(db[db_active].sub_ot[1]+3, pfill); - db_nextpri += sizeof(FILL); - - parea = (DR_AREA*)db_nextpri; - setDrawArea(parea, area); - addPrim(db[db_active].sub_ot[1]+3, parea); - parea++; - setDrawArea(parea, &db[1-db_active].draw.clip); - addPrim(db[db_active].sub_ot[1]+1, parea); - parea++; - db_nextpri = (char*)parea; - - poffs = (DR_OFFSET*)db_nextpri; - setDrawOffset(poffs, area->x, area->y); - addPrim(db[db_active].sub_ot[1]+3, poffs); - poffs++; - setDrawOffset(poffs, db[1-db_active].draw.clip.x, db[1-db_active].draw.clip.y); - addPrim(db[db_active].sub_ot[1]+1, poffs); - poffs++; - db_nextpri = (char*)poffs; - - - gte_SetGeomOffset(32, 32); - - // Sort the cube - pol4 = (POLY_FT4*)db_nextpri; - - for( i=0; i>6) <= 0) || ((p>>6) >= 4) ) - continue;*/ - - // Initialize a quad primitive - setPolyFT4( pol4 ); - - // Set the projected vertices to the primitive - gte_stsxy0( &pol4->x0 ); - gte_stsxy1( &pol4->x1 ); - gte_stsxy2( &pol4->x2 ); - - // Compute the last vertex and set the result - gte_ldv0( &cube_verts[cube_indices[i].v3] ); - gte_rtps(); - gte_stsxy( &pol4->x3 ); - - // Load primitive color even though gte_ncs() doesn't use it. - // This is so the GTE will output a color result with the - // correct primitive code. - gte_ldrgb( &pol4->r0 ); - - // Load the face normal - gte_ldv0( &cube_norms[i] ); - - // Normal Color Single - gte_ncs(); - - // Store result to the primitive - gte_strgb( &pol4->r0 ); - - gte_avsz4(); - gte_stotz( &p ); - - pol4->tpage = rendertex_tpage; - setUVWH(pol4, 0, 0, 63, 63); - - // Sort primitive to the ordering table - addPrim( db[db_active].sub_ot[1]+1, pol4 ); - - // Advance to make another primitive - pol4++; - - } - - // Update nextpri - db_nextpri = (char*)pol4; - - gte_SetGeomOffset(CENTERX, CENTERY); -} \ No newline at end of file diff --git a/examples/render2tex/makefile b/examples/render2tex/makefile deleted file mode 100644 index 59ff579..0000000 --- a/examples/render2tex/makefile +++ /dev/null @@ -1,39 +0,0 @@ -include ../sdk-common.mk - -TARGET = render2tex.elf - -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) - -INCLUDE += -LIBDIRS += - -LIBS = -lc -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lgcc - -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x - -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -AS = $(PREFIX)as -LD = $(PREFIX)ld - -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/render2tex/texture.s b/examples/render2tex/texture.s deleted file mode 100644 index e786dce..0000000 --- a/examples/render2tex/texture.s +++ /dev/null @@ -1,9 +0,0 @@ -# Assembler file for including the texture file in a more elegant manner - -.section .data - -.global tim_blendpattern -.type tim_blendpattern, @object -tim_blendpattern: - .incbin "blendpattern-16c.tim" - \ No newline at end of file diff --git a/examples/rgb24/bunpattern.tim b/examples/rgb24/bunpattern.tim deleted file mode 100644 index f233453..0000000 Binary files a/examples/rgb24/bunpattern.tim and /dev/null differ diff --git a/examples/rgb24/main.c b/examples/rgb24/main.c deleted file mode 100644 index 9f1a647..0000000 --- a/examples/rgb24/main.c +++ /dev/null @@ -1,52 +0,0 @@ -/* LibPSn00b Example Programs - * Part of the PSn00bSDK Project - * - * RGB24 Example by Lameguy64 - * - * - * This example demonstrates the 24-bit color mode of the PS1. This mode is - * not practical for gameplay as the GPU can only draw graphics primitives - * in 16-bit color depth so this feature would normally be used only for - * fullscreen graphic illustrations or FMV sequences. - * - * - * Changelog: - * - * 05-03-2019 - Initial version. - * - */ - -#include -#include -#include - -// So data from tim.s can be accessed -extern unsigned int tim_image[]; - -int main() { - - DISPENV disp; - TIM_IMAGE tim; - - // Reset GPU - ResetGraph(0); - - // Setup 640x480 24-bit video mode - SetDefDispEnv(&disp, 0, 0, 640, 480); - disp.isrgb24 = 1; - disp.isinter = 1; - - // Apply and enable display - PutDispEnv(&disp); - SetDispMask(1); - - // Upload image to VRAM - GetTimInfo(tim_image, &tim); - LoadImage(tim.prect, tim.paddr); - DrawSync(0); - - while(1) { - } - - return 0; -} \ No newline at end of file diff --git a/examples/rgb24/makefile b/examples/rgb24/makefile deleted file mode 100644 index eea866d..0000000 --- a/examples/rgb24/makefile +++ /dev/null @@ -1,41 +0,0 @@ -include ../sdk-common.mk - -TARGET = rgb24.elf - -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) - -INCLUDE += -LIBDIRS += - -LIBS = -lpsxgpu -lpsxapi -lc - -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x - -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -AS = $(PREFIX)as -LD = $(PREFIX)ld - -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.tim - -clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/rgb24/tim.s b/examples/rgb24/tim.s deleted file mode 100644 index a4432d9..0000000 --- a/examples/rgb24/tim.s +++ /dev/null @@ -1,7 +0,0 @@ -.section .data - -.global tim_image -.type tim_image, @object -tim_image: - .incbin "bunpattern.tim" - \ No newline at end of file diff --git a/examples/sdk-common.mk b/examples/sdk-common.mk index 312fda3..0503b57 100644 --- a/examples/sdk-common.mk +++ b/examples/sdk-common.mk @@ -5,10 +5,10 @@ PREFIX = mipsel-unknown-elf- # Include directories -INCLUDE = -I../../libpsn00b/include +INCLUDE = -I../../../libpsn00b/include # Library directories, last entry must point toolchain libraries -LIBDIRS = -L../../libpsn00b +LIBDIRS = -L../../../libpsn00b ifndef GCC_VERSION diff --git a/examples/system/childexec/ball16c.h b/examples/system/childexec/ball16c.h new file mode 100644 index 0000000..c79f273 --- /dev/null +++ b/examples/system/childexec/ball16c.h @@ -0,0 +1,16 @@ +unsigned int ball16c_size=192; +unsigned char ball16c[] = { +0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, +0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, +0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, +0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, +0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, +0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, +0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, +0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, +0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, +0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, +0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, +0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, +0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 +}; diff --git a/examples/system/childexec/child.c b/examples/system/childexec/child.c new file mode 100644 index 0000000..fb38b63 --- /dev/null +++ b/examples/system/childexec/child.c @@ -0,0 +1,319 @@ +#include +#include +#include +#include +#include +#include + +/* OT and Packet Buffer sizes */ +#define OT_LEN 256 +#define PACKET_LEN 1024 + +/* Screen resolution */ +#define SCREEN_XRES 320 +#define SCREEN_YRES 240 + +/* Screen center position */ +#define CENTERX SCREEN_XRES>>1 +#define CENTERY SCREEN_YRES>>1 + + +/* Double buffer structure */ +typedef struct { + DISPENV disp; /* Display environment */ + DRAWENV draw; /* Drawing environment */ + int ot[OT_LEN]; /* Ordering table */ + char p[PACKET_LEN]; /* Packet buffer */ +} DB; + +/* Double buffer variables */ +DB db[2]; +int db_active = 0; +char *db_nextpri; + + +/* For easier handling of vertex indices */ +typedef struct { + short v0,v1,v2,v3; +} INDEX; + +/* Cube vertices */ +SVECTOR cube_verts[] = { + { -100, -100, -100, 0 }, + { 100, -100, -100, 0 }, + { -100, 100, -100, 0 }, + { 100, 100, -100, 0 }, + { 100, -100, 100, 0 }, + { -100, -100, 100, 0 }, + { 100, 100, 100, 0 }, + { -100, 100, 100, 0 } +}; + +/* Cube face normals */ +SVECTOR cube_norms[] = { + { 0, 0, -ONE, 0 }, + { 0, 0, ONE, 0 }, + { 0, -ONE, 0, 0 }, + { 0, ONE, 0, 0 }, + { -ONE, 0, 0, 0 }, + { ONE, 0, 0, 0 } +}; + +/* Cube vertex indices */ +INDEX cube_indices[] = { + { 0, 1, 2, 3 }, + { 4, 5, 6, 7 }, + { 5, 4, 0, 1 }, + { 6, 7, 3, 2 }, + { 0, 2, 5, 7 }, + { 3, 1, 6, 4 } +}; + +/* Number of faces of cube */ +#define CUBE_FACES 6 + + +/* Light color matrix */ +/* Each column represents the color matrix of each light source and is */ +/* used as material color when using gte_ncs() or multiplied by a */ +/* source color when using gte_nccs(). 4096 is 1.0 in this matrix */ +/* A column of zeroes disables the light source. */ +MATRIX color_mtx = { + ONE, 0, 0, /* Red */ + ONE, 0, 0, /* Green */ + ONE, 0, 0 /* Blue */ +}; + +/* Light matrix */ +/* Each row represents a vector direction of each light source. */ +/* An entire row of zeroes disables the light source. */ +MATRIX light_mtx = { + /* X, Y, Z */ + -2048 , -2048 , -2048, + 0 , 0 , 0, + 0 , 0 , 0 +}; + +char pad_buff[2][34]; + +/* Function declarations */ +void init(); +void display(); + + +/* Main function */ +int main() { + + int i,p,xy_temp; + + SVECTOR rot = { 0 }; /* Rotation vector for Rotmatrix */ + VECTOR pos = { 0, 0, 400 }; /* Translation vector for TransMatrix */ + MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ + + POLY_F4 *pol4; /* Flat shaded quad primitive pointer */ + + + /* Init graphics and GTE */ + init(); + + + /* Main loop */ + while( 1 ) { + + PADTYPE *pad = (PADTYPE*)pad_buff[0]; + + if( pad->stat == 0 ) { + + // For digital pad, dual-analog and dual-shock + if( ( pad->type == 0x4 ) || ( pad->type == 0x5 ) || ( pad->type == 0x7 ) ) { + + if( !(pad->btn&PAD_SELECT) ) { + break; + } + + } + + } + + /* Set rotation and translation to the matrix */ + RotMatrix( &rot, &mtx ); + TransMatrix( &mtx, &pos ); + + /* Multiply light matrix by rotation matrix so light source */ + /* won't appear relative to the model's rotation */ + MulMatrix0( &light_mtx, &mtx, &lmtx ); + + /* Set rotation and translation matrix */ + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + /* Set light matrix */ + gte_SetLightMatrix( &lmtx ); + + /* Make the cube SPEEN */ + rot.vx += 16; + rot.vz += 16; + + + /* Draw the cube */ + pol4 = (POLY_F4*)db_nextpri; + + for( i=0; i>2) > OT_LEN ) + continue; + + /* Initialize a quad primitive */ + setPolyF4( pol4 ); + + /* Set the projected vertices to the primitive */ + gte_stsxy0( &pol4->x0 ); + gte_stsxy1( &pol4->x1 ); + gte_stsxy2( &pol4->x2 ); + + /* Compute the last vertex and set the result */ + gte_ldv0( &cube_verts[cube_indices[i].v3] ); + gte_rtps(); + gte_stsxy( &pol4->x3 ); + + /* Load primitive color even though gte_ncs() doesn't use it. */ + /* This is so the GTE will output a color result with the */ + /* correct primitive code. */ + gte_ldrgb( &pol4->r0 ); + + /* Load the face normal */ + gte_ldv0( &cube_norms[i] ); + + /* Normal Color Single */ + gte_ncs(); + + /* Store result to the primitive */ + gte_strgb( &pol4->r0 ); + + /* Sort primitive to the ordering table */ + addPrim( db[db_active].ot+(p>>2), pol4 ); + + /* Advance to make another primitive */ + pol4++; + + } + + /* Update nextpri variable */ + /* (IMPORTANT if you plan to sort more primitives after this) */ + db_nextpri = (char*)pol4; + + /* Swap buffers and draw the primitives */ + display(); + + } + + StopPAD(); + + return 0; + +} + +void init() { + + /* Reset the GPU, also installs a VSync event handler */ + ResetGraph( 0 ); + + /* Set display and draw environment areas */ + /* (display and draw areas must be separate, otherwise hello flicker) */ + SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + + /* Enable draw area clear and dither processing */ + setRGB0( &db[0].draw, 63, 0, 127 ); + db[0].draw.isbg = 1; + db[0].draw.dtd = 1; + + + /* Define the second set of display/draw environments */ + SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); + + setRGB0( &db[1].draw, 63, 0, 127 ); + db[1].draw.isbg = 1; + db[1].draw.dtd = 1; + + + /* Apply the drawing environment of the first double buffer */ + PutDrawEnv( &db[0].draw ); + + + /* Clear both ordering tables to make sure they are clean at the start */ + ClearOTagR( db[0].ot, OT_LEN ); + ClearOTagR( db[1].ot, OT_LEN ); + + /* Set primitive pointer address */ + db_nextpri = db[0].p; + + /* Initialize the GTE */ + InitGeom(); + + /* Set GTE offset (recommended method of centering) */ + gte_SetGeomOffset( CENTERX, CENTERY ); + + /* Set screen depth (basically FOV control, W/2 works best) */ + gte_SetGeomScreen( CENTERX ); + + /* Set light ambient color and light color matrix */ + gte_SetBackColor( 63, 63, 63 ); + gte_SetColorMatrix( &color_mtx ); + + InitPAD(pad_buff[0], 34, pad_buff[1], 34); + StartPAD(); + ChangeClearPAD(0); + +} + +void display() { + + /* Wait for GPU to finish drawing and vertical retrace */ + DrawSync( 0 ); + VSync( 0 ); + + /* Swap buffers */ + db_active ^= 1; + db_nextpri = db[db_active].p; + + /* Clear the OT of the next frame */ + ClearOTagR( db[db_active].ot, OT_LEN ); + + /* Apply display/drawing environments */ + PutDrawEnv( &db[db_active].draw ); + PutDispEnv( &db[db_active].disp ); + + /* Enable display */ + SetDispMask( 1 ); + + /* Start drawing the OT of the last buffer */ + DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); + +} \ No newline at end of file diff --git a/examples/system/childexec/child_exe.s b/examples/system/childexec/child_exe.s new file mode 100644 index 0000000..842ac88 --- /dev/null +++ b/examples/system/childexec/child_exe.s @@ -0,0 +1,6 @@ +.section .data + +.global child_exe # Insert spoopypasta +.type child_exe, @object +child_exe: + .incbin "child.exe" \ No newline at end of file diff --git a/examples/system/childexec/makefile b/examples/system/childexec/makefile new file mode 100644 index 0000000..79a27b6 --- /dev/null +++ b/examples/system/childexec/makefile @@ -0,0 +1,38 @@ +include ../../sdk-common.mk + +INCLUDE += +LIBDIRS += + +LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lc -lpsxapi + +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +CPPFLAGS = $(CFLAGS) -fno-exceptions +AFLAGS = -g -msoft-float +LDFLAGS = -g -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x + +LDFLAGS_P = $(LDFLAGS) -Ttext=0x80010000 +LDFLAGS_C = $(LDFLAGS) -Ttext=0x80030000 + +CC = $(PREFIX)gcc +LD = $(PREFIX)ld + +all: child parent + +child: build/child.o + $(LD) $(LDFLAGS_C) $(LIBDIRS) build/child.o $(LIBS) -o child.elf + elf2x child.elf + +parent: build/parent.o build/child_exe.o + $(LD) $(LDFLAGS_P) $(LIBDIRS) build/parent.o build/child_exe.o $(LIBS) -o parent.elf + elf2x parent.elf + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build parent.elf parent.exe child.elf child.exe diff --git a/examples/system/childexec/parent.c b/examples/system/childexec/parent.c new file mode 100644 index 0000000..7f577e4 --- /dev/null +++ b/examples/system/childexec/parent.c @@ -0,0 +1,305 @@ +/* + * LibPSn00b Example Programs + * + * Child Program Execution Example + * 2019 Meido-Tek Productions / PSn00bSDK Project + * + * This is a modification of the balls example, modified to execute + * a child program for this example. + * + * Example by Lameguy64 + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "ball16c.h" + + +#define MAX_BALLS 1024 + +#define OT_LEN 8 + +#define SCREEN_XRES 640 +#define SCREEN_YRES 480 + +#define CENTER_X SCREEN_XRES/2 +#define CENTER_Y SCREEN_YRES/2 + + +/* Display and drawing environments */ +DISPENV disp; +DRAWENV draw; + +char pribuff[2][65536]; /* Primitive packet buffers */ +unsigned int ot[2][OT_LEN]; /* Ordering tables */ +char *nextpri; /* Pointer to next packet buffer offset */ +int db = 0; /* Double buffer index */ + + +/* Ball struct and array */ +typedef struct { + short x,y; + short xdir,ydir; + unsigned char r,g,b,p; +} BALL_TYPE; + +BALL_TYPE balls[MAX_BALLS]; + + +/* TIM image parameters for loading the ball texture and drawing sprites */ +TIM_IMAGE tim; + + +void run_child(); + +char pad_buff[2][34]; + + +void init() { + + int i; + + /* Reset GPU (also installs event handler for VSync) */ + printf("Init GPU... "); + ResetGraph( 0 ); + printf("Done.\n"); + + + printf("Set video mode... "); + + /* Set display and draw environment parameters */ + SetDefDispEnv( &disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); + disp.isinter = 1; /* Enable interlace (required for hires) */ + + /* Set clear color, area clear and dither processing */ + setRGB0( &draw, 63, 0, 127 ); + draw.isbg = 1; + draw.dtd = 1; + + /* Apply the display and drawing environments */ + PutDispEnv( &disp ); + PutDrawEnv( &draw ); + + /* Enable video output */ + SetDispMask( 1 ); + + printf("Done.\n"); + + + /* Upload the ball texture */ + printf("Upload texture... "); + GetTimInfo( (unsigned int*)ball16c, &tim ); /* Get TIM parameters */ + + LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */ + if( tim.mode & 0x8 ) { + LoadImage( tim.crect, tim.caddr ); /* Upload CLUT if present */ + } + + printf("Done.\n"); + + + /* Calculate ball positions */ + printf("Calculating balls... "); + + for(i=0; istat == 0 ) { + + // For digital pad, dual-analog and dual-shock + if( ( pad->type == 0x4 ) || ( pad->type == 0x5 ) || ( pad->type == 0x7 ) ) { + + if( !(pad->btn&PAD_START) ) { + DrawSync(0); + run_child(); + } + + } + + } + + /* Clear ordering table and set start address of primitive */ + /* buffer for next frame */ + ClearOTagR( ot[db], OT_LEN ); + nextpri = pribuff[db]; + + /* Sort a balls snake */ + sprt = (SPRT_16*)nextpri; + srand( 64 ); + for( i=0; i<32; i++ ) { + + setSprt16( sprt ); + setXY0( sprt, + (CENTER_X-8)+(isin((counter-(i<<4))<<3)>>5), + (CENTER_Y-8)-(icos((counter-(i<<2))<<3)>>5) ); + setRGB0( sprt, rand()%256, rand()%256, rand()%256 ); + setUV0( sprt, 0, 0 ); + setClut( sprt, tim.crect->x, tim.crect->y ); + + addPrim( ot[db]+(OT_LEN-1), sprt ); + sprt++; + + } + + /* Sort the balls */ + for( i=0; ix, tim.crect->y ); + + addPrim( ot[db]+(OT_LEN-1), sprt ); + sprt++; + + balls[i].x += balls[i].xdir; + balls[i].y += balls[i].ydir; + + if( ( balls[i].x+16 ) > 640 ) { + balls[i].xdir = -2; + } else if( balls[i].x < 0 ) { + balls[i].xdir = 2; + } + + if( ( balls[i].y+16 ) > 480 ) { + balls[i].ydir = -2; + } else if( balls[i].y < 0 ) { + balls[i].ydir = 2; + } + + } + nextpri = (char*)sprt; + + + /* Sort a TPage primitive so the sprites will draw pixels from */ + /* the correct texture page in VRAM */ + tpri = (DR_TPAGE*)nextpri; + setDrawTPage( tpri, 0, 0, + getTPage( 0, 0, tim.prect->x, tim.prect->y ) ); + addPrim( ot[db]+(OT_LEN-1), tpri ); + nextpri += sizeof(DR_TPAGE); + + /* Wait for GPU and VSync */ + DrawSync( 0 ); + VSync( 0 ); + + /* Since draw.isbg is non-zero this clears the screen */ + PutDrawEnv( &draw ); + + /* Begin drawing the new frame */ + DrawOTag( ot[db]+(OT_LEN-1) ); + + /* Alternate to the next buffer */ + db = !db; + + /* Increment counter for the snake animation */ + counter++; + + } + + return 0; + +} + +// PS-EXE header structure +typedef struct { + char id[16]; + struct EXEC param; + char pad[1972]; +} EXE_HEAD; + +// Child program address +extern char child_exe[]; + +// Manually defined as its not defined in psxapi by default +void SetDefaultExitFromException(); + +void run_child() { + + // So child header is readable + EXE_HEAD *exe = (EXE_HEAD*)child_exe; + + // Copy child executable to its intended adddress + memcpy((void*)exe->param.t_addr, child_exe+2048, exe->param.t_size); + + // Enter critical section to prepare for program execution + EnterCriticalSection(); + + // Stop pads, enable auto acknowledge + StopPAD(); + ChangeClearPAD(1); + ChangeClearRCnt(3, 1); + + // Set default exception handler just in case + //SetDefaultExitFromException(); + + // Last three function calls could be relegated to + // a StopCallback() function in the future. + + // Execute child + printf("Child exec!\n"); + Exec(&exe->param, 0, 0); + + // Reset previous handler + EnterCriticalSection(); + RestartCallback(); + ExitCriticalSection(); + + // Re-init and re-enable pads + InitPAD(pad_buff[0], 34, pad_buff[1], 34); + StartPAD(); + ChangeClearPAD(0); + + // Set this program's display mode + PutDispEnv(&disp); + +} diff --git a/examples/system/console/ball16c.h b/examples/system/console/ball16c.h new file mode 100644 index 0000000..c79f273 --- /dev/null +++ b/examples/system/console/ball16c.h @@ -0,0 +1,16 @@ +unsigned int ball16c_size=192; +unsigned char ball16c[] = { +0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, +0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, +0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, +0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, +0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, +0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, +0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, +0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, +0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, +0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, +0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, +0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, +0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 +}; diff --git a/examples/system/console/main.c b/examples/system/console/main.c new file mode 100644 index 0000000..988b428 --- /dev/null +++ b/examples/system/console/main.c @@ -0,0 +1,284 @@ +/* + * LibPSn00b Example Programs + * + * Text Console Example + * 2020 Meido-Tek Productions / PSn00bSDK Project + * + * This example demonstrates a tty text console implementation for gameplay + * sections, or sections with continuously updating graphics. The console is + * brought up by the tilde key in which, execution of the gameplay section would + * get paused until the console is exited. A fully asynchronous implementation + * should be possible, but this is beyond the scope of this simple example. + * + * + * Example by Lameguy64 + * + * Changelog: + * + * April 23, 2020 - Initial version. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ball16c.h" + + +#define MAX_BALLS 1024 + +#define OT_LEN 8 + +#define SCREEN_XRES 640 +#define SCREEN_YRES 480 + +#define CENTER_X SCREEN_XRES/2 +#define CENTER_Y SCREEN_YRES/2 + + +/* Display and drawing environments */ +DISPENV disp; +DRAWENV draw; + +char pribuff[2][65536]; /* Primitive packet buffers */ +unsigned int ot[2][OT_LEN]; /* Ordering tables */ +char *nextpri; /* Pointer to next packet buffer offset */ +int db = 0; /* Double buffer index */ + + +/* Ball struct and array */ +typedef struct { + short x,y; + short xdir,ydir; + unsigned char r,g,b,p; +} BALL_TYPE; + +BALL_TYPE balls[MAX_BALLS]; + + +/* TIM image parameters for loading the ball texture and drawing sprites */ +TIM_IMAGE tim; + + +void init() { + + int i; + + /* Reset GPU (also installs event handler for VSync) */ + printf("Init GPU... "); + ResetGraph( 0 ); + printf("Done.\n"); + + + printf("Set video mode... "); + + /* Set display and draw environment parameters */ + SetDefDispEnv( &disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); + disp.isinter = 1; /* Enable interlace (required for hires) */ + + /* Set clear color, area clear and dither processing */ + setRGB0( &draw, 63, 0, 127 ); + draw.isbg = 1; + draw.dtd = 1; + + /* Apply the display and drawing environments */ + PutDispEnv( &disp ); + PutDrawEnv( &draw ); + + /* Enable video output */ + SetDispMask( 1 ); + + printf("Done.\n"); + + + /* Upload the ball texture */ + printf("Upload texture... "); + GetTimInfo( (unsigned int*)ball16c, &tim ); /* Get TIM parameters */ + + LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */ + if( tim.mode & 0x8 ) { + LoadImage( tim.crect, tim.caddr ); /* Upload CLUT if present */ + } + + printf("Done.\n"); + + + /* Calculate ball positions */ + printf("Calculating balls... "); + + for( i=0; i'); + gets(line); + + /* Exit the parser if the text entered is exit */ + if( strcmp(line, "exit") == 0 ) + break; + + /* Print the input */ + printf("You entered: %s\n", line); + } +} + + +int main(int argc, const char* argv[]) { + + SPRT_16 *sprt; + DR_TPAGE *tpri; + + int i,counter=0; + + + /* Init graphics and stuff before doing anything else */ + init(); + + + /* Uncomment this line if you don't have tty interfaces + * provided by n00brom or similar development environments with tty */ + AddSIO(115200); + + + /* Main loop */ + printf("Entering loop...\n"); + + while(1) + { + /* FIOCSCAN will return a non-zero value when there's + * input pending in tty, file handle 0 is usually stdin */ + if( ioctl(0, FIOCSCAN, 0) ) + { + /* Get the character */ + i = getchar(); + + /* If the key that's pressed is a tilde, enter the console */ + if( i == '`' ) + do_console(); + } + + /* Clear ordering table and set start address of primitive + * buffer for next frame */ + ClearOTagR(ot[db], OT_LEN); + nextpri = pribuff[db]; + + /* Sort a balls snake */ + sprt = (SPRT_16*)nextpri; + srand(64); + for( i=0; i<32; i++ ) + { + setSprt16(sprt); + setXY0(sprt, + (CENTER_X-8)+(isin((counter-(i<<4))<<3)>>5), + (CENTER_Y-8)-(icos((counter-(i<<2))<<3)>>5)); + setRGB0(sprt, rand()%256, rand()%256, rand()%256); + setUV0(sprt, 0, 0); + setClut(sprt, tim.crect->x, tim.crect->y); + + addPrim(ot[db]+(OT_LEN-1), sprt); + sprt++; + + } + + /* Sort the balls */ + for( i=0; ix, tim.crect->y); + + addPrim(ot[db]+(OT_LEN-1), sprt); + sprt++; + + balls[i].x += balls[i].xdir; + balls[i].y += balls[i].ydir; + + if( ( balls[i].x+16 ) > 640 ) + { + balls[i].xdir = -2; + } + else if( balls[i].x < 0 ) + { + balls[i].xdir = 2; + } + + if( ( balls[i].y+16 ) > 480 ) + { + balls[i].ydir = -2; + } + else if( balls[i].y < 0 ) + { + balls[i].ydir = 2; + } + + } + + nextpri = (char*)sprt; + + + /* Sort a TPage primitive so the sprites will draw pixels from + * the correct texture page in VRAM */ + tpri = (DR_TPAGE*)nextpri; + setDrawTPage(tpri, 0, 0, + getTPage(0, 0, tim.prect->x, tim.prect->y)); + addPrim(ot[db]+(OT_LEN-1), tpri); + nextpri += sizeof(DR_TPAGE); + + /* Wait for GPU and VSync */ + DrawSync(0); + VSync(0); + + /* Since draw.isbg is non-zero this clears the screen */ + PutDrawEnv(&draw); + + /* Begin drawing the new frame */ + DrawOTag(ot[db]+(OT_LEN-1)); + + /* Alternate to the next buffer */ + db = !db; + + /* Increment counter for the snake animation */ + counter++; + + } + + return 0; + +} diff --git a/examples/system/console/makefile b/examples/system/console/makefile new file mode 100644 index 0000000..0c27b55 --- /dev/null +++ b/examples/system/console/makefile @@ -0,0 +1,60 @@ +include ../../sdk-common.mk + +# Project target name +TARGET = console.elf + +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CPPFILES = $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +# Determine object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) + +# Project specific include and library directories +# (use -I for include dirs, -L for library dirs) +INCLUDE += +LIBDIRS += + +# Libraries to link +LIBS = -lpsxsio -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc + +# C compiler flags +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections + +# C++ compiler flags +CPPFLAGS = $(CFLAGS) -fno-exceptions + +# Assembler flags +AFLAGS = -g -msoft-float + +# Linker flags +LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ + -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x + +# Toolchain programs +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/system/timer/main.c b/examples/system/timer/main.c new file mode 100644 index 0000000..7d9f7b3 --- /dev/null +++ b/examples/system/timer/main.c @@ -0,0 +1,154 @@ +#include +#include +#include +#include + +/* OT and Packet Buffer sizes */ +#define OT_LEN 256 +#define PACKET_LEN 1024 + +/* Screen resolution */ +#define SCREEN_XRES 320 +#define SCREEN_YRES 240 + +/* Screen center position */ +#define CENTERX SCREEN_XRES>>1 +#define CENTERY SCREEN_YRES>>1 + + +/* Double buffer structure */ +typedef struct { + DISPENV disp; /* Display environment */ + DRAWENV draw; /* Drawing environment */ +} DB; + +/* Double buffer variables */ +DB db[2]; +int db_active = 0; + + +/* Function declarations */ +void init(); +void display(); + + +volatile int timer_calls = 0; +volatile short *timer2_ctrl = (short*)0x1F801124; +void timer_func() +{ + timer_calls++; +} + +volatile int vsync_count = 0; +volatile int tick_count = 0; +volatile int tick_value = 0; + +void vsync_func() +{ + vsync_count++; + if( vsync_count > 60 ) + { + tick_value = timer_calls-tick_count; + tick_count = timer_calls; + vsync_count = 0; + } +} + +/* Main function */ +int main() { + + int counter; + + /* Init graphics and GTE */ + init(); + + + EnterCriticalSection(); + //SetRCnt(RCntCNT2, 0xF040, RCntMdINTR); + + // NTSC clock base + counter = 4304000/560; + + // PAL clock base + //counter = 5163000/560; + + SetRCnt(RCntCNT2, counter, RCntMdINTR); + *timer2_ctrl = 0x1E58; + InterruptCallback(6, timer_func); + StartRCnt(RCntCNT2); + ChangeClearRCnt(2, 0); + ExitCriticalSection(); + + VSyncCallback(vsync_func); + + /* Main loop */ + while( 1 ) { + + FntPrint(-1, "TIMER COUNT=%d\n", timer_calls); + FntPrint(-1, "TICKS/SEC=%d\n", tick_value); + + /* Swap buffers and draw text */ + display(); + + } + + return 0; + +} + +void init() { + + /* Reset the GPU, also installs a VSync event handler */ + ResetGraph( 0 ); + //SetVideoMode(MODE_PAL); + + /* Set display and draw environment areas */ + /* (display and draw areas must be separate, otherwise hello flicker) */ + SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + + /* Enable draw area clear and dither processing */ + setRGB0( &db[0].draw, 63, 0, 127 ); + db[0].draw.isbg = 1; + db[0].draw.dtd = 1; + + + /* Define the second set of display/draw environments */ + SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); + + //db[0].disp.screen.y = 24; + //db[1].disp.screen.y = 24; + + setRGB0( &db[1].draw, 63, 0, 127 ); + db[1].draw.isbg = 1; + db[1].draw.dtd = 1; + + + /* Apply the drawing environment of the first double buffer */ + PutDrawEnv( &db[0].draw ); + + FntLoad(960, 0); + FntOpen(0, 8, 320, 216, 0, 100); + +} + +void display() { + + FntFlush(-1); + + /* Wait for GPU to finish drawing and vertical retrace */ + DrawSync( 0 ); + VSync( 0 ); + + /* Swap buffers */ + db_active ^= 1; + + /* Apply display/drawing environments */ + PutDrawEnv( &db[db_active].draw ); + PutDispEnv( &db[db_active].disp ); + + /* Enable display */ + SetDispMask( 1 ); + +} \ No newline at end of file diff --git a/examples/system/timer/makefile b/examples/system/timer/makefile new file mode 100644 index 0000000..c35c445 --- /dev/null +++ b/examples/system/timer/makefile @@ -0,0 +1,39 @@ +include ../../sdk-common.mk + +TARGET = timer.elf + +CFILES = $(notdir $(wildcard *.c)) +CPPFILES = $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) + +INCLUDE += +LIBDIRS += + +LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc + +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +CPPFLAGS = $(CFLAGS) -fno-exceptions +AFLAGS = -g -msoft-float +LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x + +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/system/tty/main.c b/examples/system/tty/main.c new file mode 100644 index 0000000..8333746 --- /dev/null +++ b/examples/system/tty/main.c @@ -0,0 +1,145 @@ +/* + * LibPSn00b Example Programs + * + * Teletype Example + * 2020 Meido-Tek Productions / PSn00bSDK Project + * + * This example showcases the uses of tty through stdio facilities. If you've + * written text console applications before, this one is not too dissimilar to + * that. Escape codes for formatting and such should work as this is more + * dependant on the terminal program used than the PS1 console itself. + * + * + * Example by Lameguy64 + * + * Changelog: + * + * April 23, 2020 - Initial version. + * + */ + +#include +#include +#include + +/* Memory viewer thing, you may use this in your own applications + * for testing or analysis */ +void memory_browser(unsigned int addr) +{ + int i,j,key; + unsigned char *ptr,*pptr; + + while(1) + { + /* Set cursor position to top-left */ + printf("\033[1;1H"); + printf("MEMVIEW 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF"); + + ptr = (unsigned char*)addr; + + /* Print contents from current location of memory */ + for(j=0; j<23; j++) + { + printf("\n%04X: ", (unsigned int)ptr); + pptr = ptr; + for(i=0; i<16; i++) + { + printf("%02X ", *ptr); + ptr++; + } + printf(" "); + for(i=0; i<16; i++) + { + if(( *pptr < 32 ) || ( *pptr > 127 ) ) + { + printf("."); + } + else + { + printf("%c", *pptr); + } + pptr++; + } + } + + /* Parse input */ + while(1) + { + key = getchar(); + if( key == 0x1B ) + { + key = getchar(); + + if( key == 0x5B ) + { + key = getchar(); + if( key == 0x41 ) // Up + { + addr -= 16; + break; + } + else if( key == 0x42 ) // Down + { + addr += 16; + break; + } + if( key == 0x35 ) // Page up + { + addr -= 16*23; + break; + } + else if( key == 0x36 ) // Page down + { + addr += 16*23; + break; + } + } + } + + } + } + +} + + +int main(int argc, const char *argv[]) +{ + int i; + char strbuff[32]; + + /* Mostly to get interrupts going for this example */ + ResetGraph( 0 ); + + /* Uncomment if you don't have an environment that provides tty access + * by default */ + //AddSIO(115200); + + /* A standby loop until 'Y' is entered */ + while(1) + { + /* Print banner */ + printf("Hello world!\n"); + printf("Press 'Y' to proceed with this demonstration.\n"); + + /* Get input for a Y character */ + i = getchar(); + if( tolower(i) == 'y' ) + break; + } + + /* Do a classic text input prompt and display the inputted text */ + printf("Enter a string, any string (no more than 32 characters):\n"); + gets(strbuff); + + printf("You've entered: %s\n\n", strbuff); + + /* Prompt entering into the memory browser */ + printf("Press a key to enter a memory browser demo...\n"); + printf("Make sure your terminal or text console supports vt100 escape codes!\n"); + getchar(); + + /* Start the memory browser interface */ + memory_browser(0x80010000); + + return 0; +} diff --git a/examples/system/tty/makefile b/examples/system/tty/makefile new file mode 100644 index 0000000..a3884ad --- /dev/null +++ b/examples/system/tty/makefile @@ -0,0 +1,60 @@ +include ../../sdk-common.mk + +# Project target name +TARGET = tty.elf + +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CPPFILES = $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +# Determine object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) + +# Project specific include and library directories +# (use -I for include dirs, -L for library dirs) +INCLUDE += +LIBDIRS += + +# Libraries to link +LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc + +# C compiler flags +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections + +# C++ compiler flags +CPPFLAGS = $(CFLAGS) -fno-exceptions + +# Assembler flags +AFLAGS = -g -msoft-float + +# Linker flags +LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ + -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x + +# Toolchain programs +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/timer/main.c b/examples/timer/main.c deleted file mode 100644 index 7d9f7b3..0000000 --- a/examples/timer/main.c +++ /dev/null @@ -1,154 +0,0 @@ -#include -#include -#include -#include - -/* OT and Packet Buffer sizes */ -#define OT_LEN 256 -#define PACKET_LEN 1024 - -/* Screen resolution */ -#define SCREEN_XRES 320 -#define SCREEN_YRES 240 - -/* Screen center position */ -#define CENTERX SCREEN_XRES>>1 -#define CENTERY SCREEN_YRES>>1 - - -/* Double buffer structure */ -typedef struct { - DISPENV disp; /* Display environment */ - DRAWENV draw; /* Drawing environment */ -} DB; - -/* Double buffer variables */ -DB db[2]; -int db_active = 0; - - -/* Function declarations */ -void init(); -void display(); - - -volatile int timer_calls = 0; -volatile short *timer2_ctrl = (short*)0x1F801124; -void timer_func() -{ - timer_calls++; -} - -volatile int vsync_count = 0; -volatile int tick_count = 0; -volatile int tick_value = 0; - -void vsync_func() -{ - vsync_count++; - if( vsync_count > 60 ) - { - tick_value = timer_calls-tick_count; - tick_count = timer_calls; - vsync_count = 0; - } -} - -/* Main function */ -int main() { - - int counter; - - /* Init graphics and GTE */ - init(); - - - EnterCriticalSection(); - //SetRCnt(RCntCNT2, 0xF040, RCntMdINTR); - - // NTSC clock base - counter = 4304000/560; - - // PAL clock base - //counter = 5163000/560; - - SetRCnt(RCntCNT2, counter, RCntMdINTR); - *timer2_ctrl = 0x1E58; - InterruptCallback(6, timer_func); - StartRCnt(RCntCNT2); - ChangeClearRCnt(2, 0); - ExitCriticalSection(); - - VSyncCallback(vsync_func); - - /* Main loop */ - while( 1 ) { - - FntPrint(-1, "TIMER COUNT=%d\n", timer_calls); - FntPrint(-1, "TICKS/SEC=%d\n", tick_value); - - /* Swap buffers and draw text */ - display(); - - } - - return 0; - -} - -void init() { - - /* Reset the GPU, also installs a VSync event handler */ - ResetGraph( 0 ); - //SetVideoMode(MODE_PAL); - - /* Set display and draw environment areas */ - /* (display and draw areas must be separate, otherwise hello flicker) */ - SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - - /* Enable draw area clear and dither processing */ - setRGB0( &db[0].draw, 63, 0, 127 ); - db[0].draw.isbg = 1; - db[0].draw.dtd = 1; - - - /* Define the second set of display/draw environments */ - SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); - - //db[0].disp.screen.y = 24; - //db[1].disp.screen.y = 24; - - setRGB0( &db[1].draw, 63, 0, 127 ); - db[1].draw.isbg = 1; - db[1].draw.dtd = 1; - - - /* Apply the drawing environment of the first double buffer */ - PutDrawEnv( &db[0].draw ); - - FntLoad(960, 0); - FntOpen(0, 8, 320, 216, 0, 100); - -} - -void display() { - - FntFlush(-1); - - /* Wait for GPU to finish drawing and vertical retrace */ - DrawSync( 0 ); - VSync( 0 ); - - /* Swap buffers */ - db_active ^= 1; - - /* Apply display/drawing environments */ - PutDrawEnv( &db[db_active].draw ); - PutDispEnv( &db[db_active].disp ); - - /* Enable display */ - SetDispMask( 1 ); - -} \ No newline at end of file diff --git a/examples/timer/makefile b/examples/timer/makefile deleted file mode 100644 index 0c1340d..0000000 --- a/examples/timer/makefile +++ /dev/null @@ -1,39 +0,0 @@ -include ../sdk-common.mk - -TARGET = timer.elf - -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) - -INCLUDE += -LIBDIRS += - -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc - -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x - -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -AS = $(PREFIX)as -LD = $(PREFIX)ld - -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) -- cgit v1.2.3