Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Coding competition 2017] Bad Apple by Psidum, Calindro, RushJet1, Sim

Reply to topic

Rate this entry!

1 (Poor) 0% 0%
2 0% 0%
3 0% 0%
4 0% 0%
5 0% 0%
6 0% 0%
7 28% 28%
8 28% 28%
9 (Excellent) 42% 42%
This poll has expired.
Author Message
  • Site Admin
  • Joined: 08 Jul 2001
  • Posts: 7664
  • Location: Paris, France
Reply with quote
Coding competition 2017] Bad Apple by Psidum, Calindro, RushJet1, Sim
Post Posted: Mon Mar 27, 2017 8:16 pm
http://www.smspower.org/Homebrew/BadAppleForSMS-SMS



Quote
Bad Apple for SMS! Goal was to get video quality as close to genesis version(s) as possible.

The following is required to run demo...
- PAL Hardware (In Fusion this is country > EU)
- SMS Generation VDP (incompatible with megadrive / genesis)
- 256 Bank Support

Code: Psidum, Calindro Music: RushJet1 Graphics: Sim1

Uses PSGlib by sverx for music playback.

Enjoy!
  View user's profile Send private message Visit poster's website
  • Joined: 31 Mar 2005
  • Posts: 90
  • Location: Georgia, USA
Reply with quote
Post Posted: Tue Mar 28, 2017 12:30 am
Here's a link to a YouTube recording of this entry.
  View user's profile Send private message Visit poster's website
  • Joined: 23 Mar 2013
  • Posts: 515
  • Location: Copenhagen, Denmark
Reply with quote
Post Posted: Tue Mar 28, 2017 6:09 am
I just watched the video on my morning commute, and think that I might have wetted my pants out of pure happiness!! Fantastic job guys. I have dreamt of this since discovering the Mega Drive version. And I thought Bad Apple required blast processing :)
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 140
  • Location: Málaga, Spain
Reply with quote
Post Posted: Tue Mar 28, 2017 8:30 am
Impressive video. This night have to test ot on emulator. Ill check the time-size relation. Vould be inyereating for intros.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 1786
Reply with quote
Post Posted: Tue Mar 28, 2017 8:35 am
Amazing work guys!!!
(Not to mention this time you could also spell my nickname correctly! :D )

A few technical questions: are you updating audio at 50 Hz or at a higher rate? How much space is the audio part taking in the ROM? (I suspect it's not a small part as PSG format is very demanding in terms of ROM space). And it's using both slot 1 and slot 2 (SEGA mapper) paging, isn't it?
  View user's profile Send private message Visit poster's website
  • Joined: 01 Feb 2014
  • Posts: 330
Reply with quote
Post Posted: Tue Mar 28, 2017 8:49 pm
Amazing stuff. It's practically perfect. Love what you did with the music. The bass in particular is awesome.
  View user's profile Send private message
  • Joined: 01 May 2011
  • Posts: 371
Reply with quote
Post Posted: Tue Mar 28, 2017 10:30 pm
Excellent stuff!
  View user's profile Send private message
  • Joined: 27 Feb 2017
  • Posts: 145
  • Location: Northern Ireland
Reply with quote
Post Posted: Tue Mar 28, 2017 10:50 pm
RushJet1 wrote
Here's a link to a YouTube recording of this entry.


Cheers for the video rushjet.

What can I say about this?
I'm frikking gobsmacked!!!
It's superb!!
What an amazing feature on the master system and will leave many thinking is this for real??
Super impressive work both visually and sound is brilliant. That heavy bass part sounds like there's some pulse width modulation and all !
Congratulations guys , really awesome.
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 11761
  • Location: London
Reply with quote
Post Posted: Wed Mar 29, 2017 10:55 am
Heh, I'd be happy with just the RushJet1 music but 25fps 2-bit video is great too. The NES versions are blown away, the video seems very close to the Mega Drive version as intended although it often seems to err on the side of 1-bit edges?

Maybe this will be the end of Bad Apple for SMS, I think it's pretty much done now...
  View user's profile Send private message Visit poster's website
  • Joined: 14 Sep 2016
  • Posts: 71
  • Location: Lyon, France
Reply with quote
Post Posted: Wed Mar 29, 2017 12:45 pm
This looks great! Super smooth and the PSG soundtrack works very well!

Is seems to be a totally different approach than mine looking at the way it uses VRAM.

Look forward to try it on my SMS :)
  View user's profile Send private message
  • Joined: 27 Feb 2017
  • Posts: 145
  • Location: Northern Ireland
Reply with quote
Post Posted: Wed Mar 29, 2017 12:51 pm
Maxim wrote
Heh, I'd be happy with just the RushJet1 music but 25fps 2-bit video is great too. The NES versions are blown away, the video seems very close to the Mega Drive version as intended although it often seems to err on the side of 1-bit edges?

Maybe this will be the end of Bad Apple for SMS, I think it's pretty much done now...


Had to check that nes version and what a difference! Nes is way more pixelized and the master system is so smooth!
  View user's profile Send private message
  • Joined: 01 Jan 2014
  • Posts: 277
Reply with quote
Post Posted: Wed Mar 29, 2017 5:59 pm
Hi.

@Sverx - The audio is 50hz, we talked about higher frequencies but it was not possible. It was a bit of a nightmare to get a call each frame due to stack abuse. The audio is 12K compressed. Both slot 1 and 2 are swapped around using sega mapper (well technically not sega mapper since they never used full 8 bit).

@Maxim - The sharper edges were intended. Taking it down to sms resolution and 2 grays the edges were very noisy.

@Gligli - Yes we came at this from very different directions. I was really happy to see your updated version. I feel your approach was far more conventional and I learned things from your discussion on forums.

Thankyou for the many kind words! I am very busy right now but hope to do a write up on how this is working, the challenges we had to over come.
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 11761
  • Location: London
Reply with quote
Post Posted: Wed Mar 29, 2017 8:11 pm
I figured the grey edges would have made it blurrier and also take a lot more ROM space :)
  View user's profile Send private message Visit poster's website
  • Joined: 25 Feb 2006
  • Posts: 442
  • Location: Belo Horizonte, MG, Brazil
Reply with quote
Post Posted: Wed Mar 29, 2017 8:36 pm
Both Bad Apples are quite nice achievements on their own way. ;)
  View user's profile Send private message Visit poster's website
  • Joined: 01 Jan 2014
  • Posts: 277
Reply with quote
Post Posted: Thu Mar 30, 2017 1:16 am
Last edited by psidum on Thu Mar 30, 2017 1:35 am; edited 1 time in total
The grey situation is pretty size neutral. For the sharpened image there is about 220,000 unique tiles after flips and invert reduced down to around 60,000 after initial tile crunch.

Then there is additional reduction as some frames have too many unique tiles for vram, some segments require streamed tiles at a rate beyond bandwidth thresholds and other things. Parser kicks and and applies compression dynamically.

Without sharper edges the original tile count is higher but the effects of compression are less noticeable so you can push the total number down to a similar level.
  View user's profile Send private message
  • Joined: 01 Jan 2014
  • Posts: 277
Reply with quote
Post Posted: Thu Mar 30, 2017 1:20 am
Some people have been asking why it does not work on Megadrive / Genesis hardware. I have no idea how explain in layman terms so I will give a technical one and let others clarify. There is around 8MB of uncompressed nametable data alone that need to fit on the ROM.

Size might seam like the big issue (and it is a big issue) but bandwidth / processing power is by far the biggest issue for 25 fps. Standard approach is to have nametable buffer and alternate frame by frame but this takes up valuable vram. Most of the time spent on this project was developing a solution that could get nametable updates done in a single vblank removing need for buffer.

An uncompressed nametable takes pretty much a full PAL vblank to write to vdp so doing it in the same time with a strong compression is not simple. The solution is multifaceted...

- Temporal compression, focusing only on nametable changes between frames.
- Difference is broken down in to rectangles similar to this discussion, http://stackoverflow.com/questions/5919298/algorithm-for-finding-the-fewest-rect...
- Bias is introduced for width over height.

A rectangle is a series of sequential nametable writes the total number determined by height. The VDP pointer needs to be adjusted if/when we need to write next row of data. To do this we need 4 registers + a 16 bit calculation + resetting the vdp pointer. Not only is this very slow but it takes up registers which are so valuable (stack is being used for reading data and z80 is otherwise very slow working with ram). Instead what we do is store only the low byte of original address, for each new line add 63 and set as low byte of vdp address, read data byte to latch full address and push over potential 256 boundary.

This came about after hours of pulling my hair out over not having enough registers to make it work. Unintuitively its also faster which was a surprise. There is obviously quite a lot more going on with the nametable solution but this is why the rom is incompatible with genesis hardware. It simply would not have been possible to get the nametables written fast enough without using this technique. A similar technique is also used to speed up streaming of tiles.

Having a single nametable frees up VRAM for better picture quality, more flexibility with front-loading tiles for high bandwidth sections, etc.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 1786
Reply with quote
Post Posted: Thu Mar 30, 2017 12:38 pm
psidum wrote
The audio is 50hz, we talked about higher frequencies but it was not possible. It was a bit of a nightmare to get a call each frame due to stack abuse. The audio is 12K compressed. Both slot 1 and 2 are swapped around using sega mapper (well technically not sega mapper since they never used full 8 bit).


Wow, it seemed to me it was updating faster. Great work tracking that from scratch (SnevenTracker?) and I'm also wondering how it could fit 12 KB... well, there's quite a lot of self-similarity in the tune so it's probably that.

I'm also curious to know if you removed the SFX support from PSGlib's PSGFrame function... that would make it way faster as you won't need to store volumes/tones in RAM nor to check if channel 2 or 3 is allocated to SFX... you might save very valuable time :)

Also, I read your post about the reason why it doesn't work on the MegaDrive VDP in SMS mode... but I don't get it. :|

Is it that this ->
Quote
set [ ] low byte of vdp address, read data byte to latch full address and push over potential 256 boundary.

... doesn't work on MD?
  View user's profile Send private message Visit poster's website
  • Joined: 01 Jan 2014
  • Posts: 277
Reply with quote
Post Posted: Fri Mar 31, 2017 3:19 am
Yes that is the incompatibility. MD expects command words to be 16bit.

The solution is not dissimilar to the more commonly used HL, manipulate L for quick navigation within a 256 boundary of data in general z80 programming except here we can push in to next 256 boundary by setting L to 255 and reading a byte to auto increment H, or in this case VDP pointer.

If you hold up + both buttons on incompatibility screen it will run the rom anyway regardless of incompatibilities. Concat the rom to 1MB and you can see the first min or so of video on you everdrives, even in NTSC (it will be faster).
  View user's profile Send private message
  • Joined: 01 May 2011
  • Posts: 371
Reply with quote
Post Posted: Fri Mar 31, 2017 11:55 pm
Side by side comparison with Mega Drive and NES.
  View user's profile Send private message
  • Joined: 28 Jan 2017
  • Posts: 140
  • Location: Málaga, Spain
Reply with quote
Post Posted: Sun Apr 02, 2017 2:33 pm
Wow! Wow! WOW! how smooth animation here. I suppose the palette wild reduction lets to do things like this. Also, very good music arrangement. Remember the dos demoscene years. Well done!
  View user's profile Send private message
  • Joined: 01 Jan 2014
  • Posts: 277
Reply with quote
Post Posted: Tue May 16, 2017 3:27 am
Hi

Here is the rom source for project.

The original video code was written around this time last year and saw various updates over the course of the year. The code for animation is in /libraries/graphlib.inc. I didn’t bother cleaning up other code since its just displaying images and fades. The encoder is not in a state fit for human consumption right now. Some additional info…

    - The description I gave about vdp address latching was accurate for earlier versions however a later update was made to get MD compatibility.

    - Originally intended to be black and white (1 bitplane) and fit in 1MB. Became apparent this goal was not possible without major rework so switched to grey scale (2 bitplane) and 4MB.

    - Performance issues associated with 2 bitplane graphics forced us to revert tilestream code back to incompatible version breaking MD / Genesis compatibility yet again.

    - Decompressor uses stack for performance gains. Can take between 1 to 3 vdp frames to decode 1 video frame. Its very rarely 3. Decompressor pads additional vdp frame when only one frame is used to keep in sync.

    - PSGlib is called 50 fps. During tile streaming interrupts are turned off on z80 but left on on VDP. Control port is periodically polled to check for required PSGlib calls.


Everyone was busy when this was released. Should have given additional thanks to the following people.

    Kabuto: Reviewed code and suggest improvements. Major source of inspiration.
    Efry: Author of Z80Editor dev environment + support and encouragement.
    Kagesan: Support and encouragement.
    Maxim: Technical documentation. Modified aplib code used for images.
    Charles McDonald: Technical documentation writer extraordinaire!
    Everyone at SMS Power for making the SMS Dev scene the great scene it is!

sms_bad_apple.zip (4.16 MB)

  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 1786
Reply with quote
Post Posted: Tue May 16, 2017 9:17 am
psidum wrote
PSGlib is called 50 fps. During tile streaming interrupts are turned off on z80 but left on on VDP. Control port is periodically polled to check for required PSGlib calls.


Cunning! :) BTW, did you strip the unused features from PSGlib (to make it faster) or did you use it out-of-the-box? A stripped down PSGlib version would be much faster (I'm thinking about having no checks for SFX, no volume attenuation and so on...).
I can make such a version, if you need it :)
  View user's profile Send private message Visit poster's website
  • Joined: 01 Jan 2014
  • Posts: 277
Reply with quote
Post Posted: Tue May 16, 2017 1:57 pm
It uses the full library. I have been meaning to strip it back, I think it would be good to put out there.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 1786
Reply with quote
Post Posted: Thu May 18, 2017 2:45 pm
PSG_lib "minimalistic" - PSGFrame shouldn't require more than 11 scanlines in worst case.
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 140
  • Location: Málaga, Spain
Reply with quote
Post Posted: Thu May 18, 2017 9:22 pm
sverx wrote
PSG_lib "minimalistic" - PSGFrame shouldn't require more than 11 scanlines in worst case.


... if you check astroforce pause, you will find that the music plays from init when you unpause. A pause-resume (only for music) maintaining sound effects active would be great!
  View user's profile Send private message
  • Joined: 01 Jan 2014
  • Posts: 277
Reply with quote
Post Posted: Fri May 19, 2017 2:28 am
<3 Sverx
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 1786
Reply with quote
Post Posted: Fri May 19, 2017 8:06 am
eruiz00 wrote
... if you check astroforce pause, you will find that the music plays from init when you unpause. A pause-resume (only for music) maintaining sound effects active would be great!


from PSGlib's readme:
Quote
If you need to temporary suspend audio, use PSGSilenceChannels and stop calling PSGFrame and PSGSFXFrame. When ready to resume, use PSGRestoreVolumes.


but I didn't think about pausing music while leaving SFXs on. I will think about that, thanks for the suggestion! :)
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 1786
Reply with quote
Post Posted: Fri May 19, 2017 8:07 am
psidum wrote
<3 Sverx


not in public, mate ;)
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 1786
Reply with quote
Post Posted: Fri May 19, 2017 1:05 pm
I'm working on PSGResume - to resume a tune previously stopped with PSGStop.
Will be integrated into devkitSMS soon.
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 140
  • Location: Málaga, Spain
Reply with quote
Post Posted: Fri May 19, 2017 1:07 pm
Great!
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 1786
Reply with quote
Post Posted: Fri May 19, 2017 2:18 pm
Done. It wasn't that hard ;)
Let me know if something isn't working as expected.
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 140
  • Location: Málaga, Spain
Reply with quote
Post Posted: Fri May 19, 2017 5:24 pm
<3 Sverx
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 1786
Reply with quote
Post Posted: Fri May 19, 2017 5:33 pm
eruiz00 wrote
<3 Sverx


LOL! :D
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!