PPCenter :: devblog

PPcenter. Arts and craft for my Sega Saturn. Since 1847 :D

Bit shift in Saturn minimalistic C program

Written by cafealpha 2 comments
While making a Saturn program running directly from ROM, constraint is usually to have program as small as possible. Why ? Because I would like to make Pseudo Saturn Kai continue supporting Action Replay, which have limited ROM size

So, in that situation, I use homemade, minimalistic stdlib, containing usually only memcpy and memset functions, and everything goes well.
But for some reason, current program was begging for __ashlsi3 and __ashrsi3 functions.
... What's these things ? __ashlsi3 is an assembly function doing left shifts of data, and as you probably guessed, __ashrsi3 does the same, but with right shifts

No problem, let's ask my friend google, and copy & paste theses functions without minding about their contents Theses functions are standard functions provided by C library, so sources can be found here and there.


An example of what __ashrsi3 function looks like

A day after that, here comes the time to do basic testing of this ROM code
Let's first start with simple things such as screen display ...


Text display ... not as expected ?!

Hrm, it's probably a problem in my printchar routine ?

printchar source code : this is the core thing
behind text display in my programs


But that's a very long time I didn't touched this routine, which works well on Pseudo Saturn Kai, and works even better in vdp1ex from Charles MacDonald sample programs, because all my printchar routines come from there
But just in case of, let's try to tune one " <<3 " into " *8 " in the code above, and see if that changes something. Theses two operations are equivalent, so this should give the same result, but ... Saturn screen becomes all black

Okay, there's definitely something weird regarding that printchar, but I just re-used it as-is from other project, so what's going wrong with my it ?!
[...]
And then (finally) a light-bulb above my head appears Maybe there's something wrong regarding the __ashlsi3 and __ashrsi3 routines ?
And, yes there was something wrong regarding theses routines ... I wrote a paragraph about them on the first half of this article, so it would be surprising the problem came from somewhere else

In more accurate words, routines are OK, which is normal since they are written by people smarter than me But the calling convention of __ashrsi3 was not as my gcc was expecting ?
Well, that's just a guess from the display results, because it seems to display the same pixel 8 times on each row of a given character, which may happen when ignoring shift parameter in __ashrsi3 function.

Anyway, rather than finding in details what's wrong, let's fix the problem First, with assembly by hand, in desperately trying to change input parameter handling ... I don't remember exactly what I wrote, but that was something like pushing a register to stack, moving parameter to it, finally restoring register, putting nop instructions everywhere, etc ... nothing difficult, but over my extent in assembly programming

The result is ... a mixed success :

Trying to modify __ashrsi3 routine by hand ... well, it seems that
some shift values are not correctly handled


Okay, so let's re-ask google about that __ashrsi3 routine ... and a different implementation arrives in search results. Let's try it


__ashrsi3

And the execution result :

Execution result with second version of __ashrsi3 function

Yeah, it works this time !!! And don't ask me why, because I didn't took time in understanding what's different in that second version of __ashrsi3 function
And, rather than understanding why it works ... let's close that assembly pandora box before some other mystic bugs pop from it

I will probably see about this in the future, but that was absolutely out of the scope of today's programming, and in software world, too much digression leads to freeze of projects, which I would like to avoid in order to go forward to next pending project 

As a example, I started to adapt yeti3d engine to Saturn in 2010 (7 years ago !), and this ended in ... developing a SD card based memory cartridge for Saturn !
The point above is is not a joke : menus used in my yeti3d adaptation are the origin of menus used in Pseudo Saturn Kai, which shows the continuity (co-consanguinity ? ) in my projects. And after getting yeti3d working a bit, I really would like to load levels from something else than CD-ROM, which was from PC (via adequate link cable) on a first time, and which will (should ?) then evolve to SD card.
That would be cool to make a Saturn game not requiring to burn CD-ROM somedays, but before that I need to finish neighboring side quests


Evolution of my Saturn projects

To conclude this article, let's say it was terribly fun to see some bits of the internals behind C language
By the past, I remember I did something similar with my yeti3d adaptation, but remained at "C language level" : optimization done at that time was (IIRC, ) to avoid 4 bits shifts, because theses are not available in a single SH-2 CPU instruction. Avoiding 4 bits shifts was simply done by merging two fixed point operation in a single one (or something like that : I did this 7 years ago !), and this actually gave some improvements in 3D scene rendering Theses were the good times ... I sometimes think "I'm Getting Too Old For This Shit", but that's only to motivate to finish my old projects

But before that, Pseudo Saturn Kai, and then Kicad and Quartus are waiting for me


BTW, in the case you wondered about what was today's programming session, you probably guessed it was about exception handler addition to Pseudo Saturn Kai. This not a new feature, since it was available in Pseudo Saturn 0.83x ... in fact, I grabbed some sources from Pseudo Saturn 0.83x in order to implement this exception handler (thank you CyberWarriorX !) This exception handler will be available as a small add-don to cheat codes feature in Pseudo Saturn Kai next major release.

Read more Bit shift in Saturn minimalistic C program

Gamer's Cartridge on Twitter !

Written by cafealpha no comments
That's always a pleasure to see Gamer's Cartridge users having fun with their Saturns, and showing it on social networks
I'm not registered to Twitter, and don't like self-promotion of my projects else where than on my homepage ... but I like self-flattery (), so let's put here some pictures of Gamer's Cartridges I could find on Twitter



Dezaemon DB's Gamer's Cartridge
Many thanks to him for Dezaemon DB homepage !



Nidone's Gamer's Cartridge
"Unfortunately, I forgot to bring my Saturn from my parents house"



Unagiman's Gamer's Cartridge
"I can't remember where I stored Dezaemon 2 CDROM (´Д`)"




Unagiman's Skeleton Saturn, very shibui


Beeraka's cartridge.
Beeraka-san is the author of Dezaemon-themed labels !
Many thanks to him for the good work !

#MakeSaturnGreatAgain

Read more Gamer's Cartridge on Twitter !

Pseudo Saturn FAQ, May 2017 edition

Written by cafealpha no comments
Here is a small FAQ about Pseudo Saturn, so that it may help people experiencing troubles when installing or using Pseudo Saturn, and also ... reduce the number of inquiries in my mailbox

Pseudo Saturn 0.832 "Booting CD ... Error 1" message when trying to load a game.


The "Booting CD ... Error 1" message.
Special Thanks to C.L. for reporting the problem and sending the picture

This problem happens with Pseudo Saturn 0.832, both "no logo" initial build and final release with classy logo.

It concerns :
 - A specific hardware revision of Saturn : Japanese grey model 1 (95% sure), with power supply connector screwed to Saturn top case (not so sure).
 - Any game or application on burned on CD-R

So if you have Pseudo Saturn 0.832 and the "wrong" (incompatible) hardware revision of Saturn, it's not possible to play any CD-R copy of your games, and consequently can't upgrade your cartridge to other version of Pseudo Saturn, since it requires to boot a CD-R

Annoying isn't it ? The countermeasure is to either :
 1. Install latest Pseudo Saturn Kai on your Saturn cartridge
 2. Use another Saturn, compatible with Pseudo Saturn 0.832 :
      - Model 2 Saturns are 99% safe : I didn't received any "Boot Error 1" report with model 2 Saturn.
      - Please try on another model 1 Saturn only if you were lucky that day, else please be sure that this other Saturn won't be compatible too

Owning a spare and compatible Saturn -or being friend with somebody owning one- is the best solution, since it allows to both upgrade to Pseudo Saturn Kai, and to play games compatible with "JHL (PS 0.832)" game loader.

Owning only 0.832 incompatible Saturn(s) will bring you to "install Pseudo Saturn Kai on a bare Saturn" step, so basically requires to open your Saturn, watch swap trick tutorials on youtube, fail several times in trying that ('%)=(&$ swap trick, finally success in installing Pseudo Saturn Kai , look for one missing screw in order to put back Saturn top cover, re-open the Saturn in order to remove the tape on CD-ROM lid open switch, and finally put back the Saturn in its original condition

Long install steps ? Yes, but at the end the problem will be fixed (if not, please contact me)
However, there's a limitation when using Pseudo Saturn Kai on model 1 incompatible Saturns : the few games not compatible with Pseudo Saturn 0.831 won't be playable
Incompatible games are the ones marked as requiring Pseudo Saturn patcher utility, in Pseudo Saturn Kai compatibility list. Notable examples are Panzer Dragoon Saga, Batman Forever and Alien Trilogy.

You sold a kidney in order to buy original discs of Panzer Dragoon Saga, and really want to play their CD-R copies on your model 1 Japanese Saturn so that original discs won't be damaged ?

Except selling the remaining kidney in order to buy a Rhea/Phoebe (), the only solution is to wait until a new version of Pseudo Saturn Kai is released, and hope I find a fix to this problem.
While waiting for new version of Pseudo Saturn Kai, how about trying games that Pseudo Saturn Kai can play with its good old "CWX (PS 0.831)" game loader ? I would for example recommend NiGHTS into dreams, Shining Force 3 series, and also Virtua Fighter Kids



"Firmware file read error !" message when trying to install Pseudo Saturn Kai

"Firmware file read error !" message (hard to read, sorry).
Grabbed from reddit, special thanks to yoqu for reporting the problem

First, I fixed error text display in Pseudo Saturn Kai's latest release (v6.074) : it is now displayed with white background color. Readability varies from a TV monitor to another, so please contact me if that's still not readable on your TV

This problem is generally caused by incorrect timing when performing swap trick, which makes Saturn booting Save Data Manager and Flasher utility from CD-R, but not being able to read files from CD-R after that.
Another causes may be Saturn's laser incorrect calibration, or affinity problem between Saturn CD block and CD-R brand, or burn settings.

The countermeasure is simple : please use Pseudo Saturn Kai alternate flasher utility, located in Pseudo Saturn Kai latest archive → pskai_alternate_flasher.iso. This requires another CD-R, but this will work
And, burning Pseudo Saturn Kai Save Data Manager and Flasher utility (pskai_sdm_flasher.iso) wasn't a waste, since it will boot correctly after flashing your cartridge to Pseudo Saturn Kai. Save Data Manager contains many save data to import to your Saturn, so you probably want to use them in order to start playing your favorite game elsewhere than level 1

So, what's the magic behind Pseudo Saturn Kai alternate flasher utility ? nothing really special in fact : both flasher executable and Pseudo Saturn Kai firmware data are packed in a single Saturn executable file. So as firmware data is loaded just after performing swap trick, file read error won't happen


Definitely not a smart way to counter a problem,
but it works, which is the most important


This "alternate" flasher utility was developed before Pseudo Saturn Kai, and used in Pseudo Saturn 0.83x flasher utilities. I then developed an "all in one" Save Data Manager & Flasher utility on a single CD-ROM which allows to flash cartridge, manage save data, etc.

I though this would make the "alternate" initial flasher utility obsolete, so that it was dropped in Pseudo Saturn Kai 6.036 and 6.037 releases ... unfortunately I was reported about that "Firmware file read error !" problem after that
So as a countermeasure, I restored this utility from Pseudo Saturn 6.074. Sorry for the troubles caused

Additionally, some more informations about this problem are displayed in current (W.I.P.) Pseudo Saturn Kai version.

Updated error message in flasher utility.

Pseudo Saturn Kai development continues ! Stay tuned

Read more Pseudo Saturn FAQ, May 2017 edition

Similar looking kanji definitions file update

Written by cafealpha no comments
It's been a while I didn't received an email not related to Saturn from my homepage, so I was quite happy when siikamiika asked me if he could safely license similar kanjis definition file in MIT licence in his similar-kanji project


What is "similar kanjis definition file" ? It is a text file used in "My JWPce" which defines ... kanjis looking similar
The original idea about this is not from me : I initially found this feature in kanji.free.fr (Japanese → Omelette du fromage online kanji dictionary), and thought it would be cool if this feature could be available directly from my favorite Japanese electronic dictionary.
So I build this "similar kanjis definition file", and added support for it in "My JWPce".

data/images/20170220_jpwce_similar_kanjis.tb.png
Example of in JWPce's kanji information
dialog : "似" looks like "以",
"代" and "伐"

If you're Japanese, or were learning Chinese characters from elementary school, this definition file is probably a complete nonsense for you, since you know how to enter the correct kanji from keyboard on first try.
But that's not the same done for foreigners who started to learn Japanese in their twenties, so that this feature helped me a lot when learning new kanjis :
 1. In JWPce, enter a kanji similar the new one you can't read
 2. Search for that new kanji in similar kanjis list
 3. ????
 4. Profit !

So of course, MIT licensing of this file is OK, and I was also glad to overwrite my old definition file with siikamiika's version, so that I could enjoy all new entries added in this version
Open source is love, open source is life, thank you siikamiika

Read more Similar looking kanji definitions file update

Gamer's Cartridge out of stock :]

Written by cafealpha 5 comments
Out of stock ":]". I'm glad to have finished this batch
I don't plan to sell Gamer's Cartridge for a while, because stock of parts to build theses cartridges (electronics components, PCBs, labels, etc) is currently very low here. I'm even lacking of bubble paper used when shipping cartridges

So, what's next ? Of course, Saturn stuff  I plan to use this "break" in cartridges manufacturing and sales in order to continue Pseudo Saturn Kai development.
Main feature to add is cheat codes, which is a bit "heavy" one to implement, because processing in order to make cheat codes working isn't documented in details.
But that will be done ! Also, there are some side quests here and there regarding Pseudo Saturn Kai features. I plan to implement as far I can, so it will be limited only by my free time, my motivation, and flash ROM remaining on cartridge

data/images/20170215_sgc_v33b_gerber_preview.tb.png
Gerber preview before ordering PCB on
Seeed Studio, very classy and realistic

Edit (2017/05/11) : finally back in stock
I catched the occasion to make some minor improvements to my homepage, such as adding anchor link to some sections, adding some directions for Japanese users, etc ... and I'm already full up with writing HTML

Edit (2017/05/12) : half of the stock already reserved oO
data/images/20170512_escalated_quickly.jpg
Cartridges are assembled by hand, hence stock is small, but I'm impressed anyway

Read more Gamer's Cartridge out of stock :]

Rss feed of the articles