CPCWiki forum

General Category => Programming => Topic started by: TCMSLP on 11:45, 25 October 12

Title: Help: Convert, display image, progressive loading (tape)?
Post by: TCMSLP on 11:45, 25 October 12



Hi All,


Firstly, I'm a bit of a noob - I grew up with the CPC but only ever had the 464 so my programming was limited to BASIC.  I'm not against learning Z80 assembler (I learnt 68000 + PIC assembly so it's not beyond me) - however, I'm looking for the easiest way to achieve what I want.  My main OS is Linux and I'm aware of the basic cross development tools available, including CPCSDK and gfx2crtc which I'm sure will form part of the solution here.


On a basic (no pun intended) level I'd like to:-


1) Convert a monochrome (green on black) image to CPC '.scr' (?) format
2) Transfer image to CPC
3) Find/write loader routine to load image from tape and plot image 'live' (as data is read)


I'm assuming I'd need to convert the image file then either use an emulator to shift the data to CPC memory, or transfer to an emulator using an emulated floppy, then write some BASIC (or Z80) code to dump the memory contents (image data) to tape, plus add a loader?   The loader would need to plot the display in real time as data is being loaded from tape (a live progressive image display).  What's the easiest method of doing this? 


As the image is quite basic I was considering simply capturing each pixel and dumping it into a BASIC 'data' (?) statement, so the loader could itself contain the image data - however, I don't think there's any way I could plot the image 'live' like this;  I'm assuming I'd at least need the data stored in different blocks and use an interrupt routine to load & plot?  This is a bit beyond my abilities :(


At a more advanced level - it would be awesome if I could have a loader which would then either stream data (complete with corrupted data) to the screen ignoring loading errors, or, perhaps use some form of basic error correction to reduce screen corruption.


Why?  I'm a musician and I hope to embed a CPC image within a piece of music!


For examples of my previous work embedding data in music see Coherer: Making of 'Satellite' (SSTV, Electro) - YouTube (http://youtu.be/8Il_V5kLeNA?hd=1)


Any help / advice / code appreciated :)






Steve / Coherer
(or TCM/Slipstream in demoscene land)
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: Bryce on 12:07, 25 October 12
Hi and welcome to the forum,

Loading a screen from tape directly to the screen area, does the "progressive" effect you're talking about without the need of any special routines: Load "MyScreen.scr", &C000
To save a screen on the CPC is more or less the same, but you have to define the length and tell it to save in binary too: Save "MyScreen.scr", b, &C000, &4000

Getting the picture from the PC to the CPC might prove difficult if you don't have a floppy drive. As far as image converters are concerned, there are several programs to convert a picture to scr colours and format.

Bryce.
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: TCMSLP on 12:46, 25 October 12



Thanks Bryce!  Looks like this may be a lot easier than I thought!


If the rom 'load' routine simply dumps data from tape directly into graphics memory - am I right in thinking any errors would be ignored, causing corruption but not preventing further reads?


Ultimately, I guess I'll have to try it :)


Thanks again!




Steve
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: arnoldemu on 13:22, 25 October 12
I am not sure I understand completely.

I understand you make music. So when a person listens to it they hear music, but when the computer hears it, it sees data and it loads a picture? Nice..

It reminds me of those cd tracks where you have to go past the beginning or far past the end to get extra songs.

The standard block loader would not be so good here, because it has a checksum for each block. If there are errors it stops loading and requires you to rewind to try again.

If you used the "headerless" variant of this loader it would reset the cpc on a load error, here it sees the error, and returns to your program which would then normally just quit with a reset happening.

The best would be to use an alternative loader. First a 1 file block loader to start, then the rest is in the special loader.
My advice is to use the 2cdt tool to first add a normal block file, then add a spectrum data block. Spectrum loader has a checksum at the very end, you can choose to ignore that, if an error comes in the middle it could be modified to just continue and display garbage, or to quit.
it's more simple.

You can do this using 2cdt tool. Unofficial Amstrad WWW Resource (http://www.cpctech.org.uk/) look in the downloads
you can get the tapeloader from my conversion of blue angel.

go to cpcfreak.cpc-live.com, download the source and look for tapeload.asm

there should be enough there to get you started but feel free to ask.


Now, if you had said "I want music while it loads", e.g. cpc playing music and loading, that's a lot more difficult.. not impossible but more difficult.

This demo on spectrum takes it to the extreme, but it is also possible, but not done yet, on the cpc:
"Ahh.. the tape loading era!" by Ate Bit (http://www.youtube.com/watch?v=OJ01EDhL0VM#)

This demo has  loader playing music which both streams in data to be displayed, and actually loads something which is run after.

I have also seen on the spectrum 2 other ways to have music during loading.
One encodes the loader data in a way that it also sounds like music.. here the music playback is effectively for free because it comes from how we hear it.

Another actually plays sound using the ay sound chip and is more cpu intensive.


Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: TCMSLP on 14:34, 25 October 12
Interesting comments and plenty to start researching.  Thanks again!


And yes, I'd include a non-corrupted standard data block, which would then in turn load additional data (without CRC checks) which would be embedded in audio/music, much like the SSTV image being built up (with corruption) in the video I posted above.


I have no idea how well this would work, if at all, in practice.  SSTV is analog so reasonably forgiving in terms of errors/noise.  I imagine flipping bits randomly will be seriously destructive.




Steve
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: McKlain on 16:57, 25 October 12

This discussion reminded me of this:

ZX Spectrum plays Imperial March with loading noise (http://www.youtube.com/watch?v=ScKKkVtB2lc#)




Oh wait, there's more:


Tap music (ZX-Spectrum) (http://www.youtube.com/watch?v=lpEDBik0x9U#)




Gotta love 1bit music  ;D
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: TFM on 19:19, 25 October 12
Well, why not playing a regular music tape then? Quality will improve  ;)
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: AMSDOS on 00:35, 26 October 12
Quote from: Bryce on 12:07, 25 October 12
Hi and welcome to the forum,

Loading a screen from tape directly to the screen area, does the "progressive" effect you're talking about without the need of any special routines: Load "MyScreen.scr", &C000
To save a screen on the CPC is more or less the same, but you have to define the length and tell it to save in binary too: Save "MyScreen.scr", b, &C000, &4000
It's also important to have the '!' in front of the filename when loading or saving to or from the screen when dealing with tape  ;)
e.g. Load"!screen.scr",&C000
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: TCMSLP on 10:54, 26 October 12



I'll check out the videos when home this evening :)

I've googled this quickly but with no luck - what does the "!" in a load statement achieve?

Thanks,




Steve
TCM/SLP
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: AMSDOS on 11:09, 26 October 12
Quote from: TCMSLP on 10:54, 26 October 12

I've googled this quickly but with no luck - what does the "!" in a load statement achieve?


What "!" does (particularly on tapes) is it stops any loading messages being displayed onscreen (which looks something like this):


"Loading SCREEN.SCR Block 1"


which gets updated with every Block - 7 Blocks I think in a Screen file?


Having the explanation mark there won't mess up a display image. From Disc it won't display this text (as it loads in the screen), though having the explanation mark there won't be a problem with Disc Drives either.
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: Bryce on 11:10, 26 October 12
The ! supresses the on-screen tape loading messages such as "Loading Block 1" etc.

Bryce.

Edit: Oh, CP/MUser got there before me :)
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: TCMSLP on 12:00, 26 October 12



Fantastic.  You guys rock.   I'm already looking at Z80 assembler (and the C threads posted on this forum) in addition to the CPC BIOS documentation.  If I get the time (amongst a million other projects) I'd love to put a proper demo together :)
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: TFM on 15:53, 26 October 12
Quote from: CP/M User on 11:09, 26 October 12

What "!" does (particularly on tapes) is it stops any loading messages being displayed onscreen (which looks something like this):


"Loading SCREEN.SCR Block 1"


which gets updated with every Block - 7 Blocks I think in a Screen file?


Having the explanation mark there won't mess up a display image. From Disc it won't display this text (as it loads in the screen), though having the explanation mark there won't be a problem with Disc Drives either.


What the "!" really does IS to omit the question "Press play and then any key". So it's function is to start loading right away, without waiting for the user to press a key.
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: db6128 on 18:25, 26 October 12
Just since no one really responded to it:

Quote from: TCMSLP on 12:46, 25 October 12If the rom 'load' routine simply dumps data from tape directly into graphics memory - am I right in thinking any errors would be ignored, causing corruption but not preventing further reads?
Yes, in theory! But in practise, the data-encoding system - which is the same as the one used for code - is impressively resilient. I, presumably among many other users, have original tapes that still load, code and screens and whatever else, with perfect accuracy.*

Moreover, the default mean frequency of the bitstream is 1000 Hz (i.e. 666 Hz for low bits, 1333 Hz for high bits), but the CPC can be programmed to operate with a mean frequency of up to 2500 Hz, such as SPEED WRITE 1's 2000 Hz; these make the default settings look very cautious and indicate that they leave plenty of room for error (prevention).

Specific to your idea, presumably you'll be able to obtain a new - or at least slightly newer ;) - cassette tape, and so you shouldn't have to worry about errors at all.


*Having said that, not all tapes fare quite so well: I tried my tape of Fantasy Dizzy yesterday, and it loaded the title screen but then locked up with a blank screen after loading all of its data, i.e. when it should have launched the game. Is this a known issue, or am I just unlucky?
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: jbaudrand on 21:51, 26 October 12
You should try the game birdie tape version, there's music during the loading of the program. Was really impressed by this and still today.
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: AMSDOS on 22:51, 26 October 12
Quote from: TFM/FS on 15:53, 26 October 12


What the "!" really does IS to omit the question "Press play and then any key". So it's function is to start loading right away, without waiting for the user to press a key.


That's right.


Does anyone know the file structure layout produced from JL-COPY?


Originally I was converting my old AMSOFT games (on a 464) from JL-COPY into really compacted files by adjusting the baud rate to 3500 or something. But the interesting thing about those files was they started off like a Loader with a header, there were 2 Blocks, though the 2nd Block was one lengthy block (like a Headerless file), which loaded in the rest of the game.


I thought them Firebird loaders were pretty cool, they kind of made fun to wind the tape back if there was an error.  :D



Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: McKlain on 13:42, 27 October 12
Quote from: CP/M User on 22:51, 26 October 12
Originally I was converting my old AMSOFT games (on a 464) from JL-COPY into really compacted files by adjusting the baud rate to 3500 or something. But the interesting thing about those files was they started off like a Loader with a header, there were 2 Blocks, though the 2nd Block was one lengthy block (like a Headerless file), which loaded in the rest of the game.



I remember that there was some other tape copying program that made this too, 1 normal block, a long second block and sometimes a third block.
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: arnoldemu on 13:43, 27 October 12
Quote from: McKlain on 13:42, 27 October 12

I remember that there was some other tape copying program that made this too, 1 normal block, a long second block and sometimes a third block.
2cdt tool can make files like this.
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: McKlain on 13:44, 27 October 12
The thing is that I can't remember the name of the copier  ::)
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: db6128 on 13:54, 27 October 12
I spent time reading the Whole Memory Guide's and Firmware Guide's descriptions of how data are encoded on tape and smiling to myself as I recognised specific features and structures from my memory of the sounds. Is this cool (Y/N) ;)

Hey, how do we implement the Spectrum-style scrolling border, again? I seem to recall having done it, or at least read how it's done, in the past; but I've forgotten. Presumably it involves calling SCR SET BORDER (&BC38) whenever the input bit changes or something.
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: arnoldemu on 13:56, 27 October 12
Quote from: db6128 on 13:54, 27 October 12
I spent time reading the Whole Memory Guide's and Firmware Guide's descriptions of how data are encoded on tape and smiling to myself as I recognised specific features and structures from my memory of the sounds. Is this cool (Y/N) ;)

Hey, how do we implement the Spectrum-style scrolling border, again? I seem to recall having done it, or at least read how it's done, in the past; but I've forgotten. Presumably it involves calling SCR SET BORDER (&BC38) whenever the input bit changes or something.
You need to re-write the loader and hit the hardware directly or use one that has been done already.
interrupts are disabled while the loader is active.

it's almost like calling scr set border, but done the hardware way.


Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: db6128 on 13:58, 27 October 12
Ah yeah. Re-write CAS READ, you mean? And of course it'd be done directly rather than via SCR SET BORDER - that was silly of me, haha. Back to the firmware guides...
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: Nich on 18:43, 04 November 12
Quote from: jbaudrand on 21:51, 26 October 12
You should try the game birdie tape version, there's music during the loading of the program. Was really impressed by this and still today.
I tested this using CPCE. I don't know if the sounds that I hear while the title screen is loading could be classed as 'music'! :laugh:

Seriously, it is impressive (and very rare) to hear music being played while loading data from cassette. I know that several Firebird games also played music while the game was loading, and all of these tunes were composed by Melvyn Wright.
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: Gryzor on 19:35, 04 November 12
Could be that CPCE plays the tape sounds and it conflicts with the actual music?
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: TCMSLP on 23:16, 04 November 12

Wow.  I forgot how slow loading from tape was.  Dumping 16k of screen mem to tape takes ~3 minutes.

Makes me wonder why people ever bothered with loading screens 'back in the day';  I guess they used some form of compression, but even so - loading screens must have added valuable minutes to loading times.

Now I have the basics working using standard load/save commands from BASIC, I'd like to experiment with dumping the whole 16k block to tape/disk in one block.  I see the CAS_READ and CAS_WRITE ROM routines seem to allow this; I'm guessing as I need to pass values via HL and DE registers I'll need to do this in assembly language - or can I 'poke' the HL and DE registers from BASIC?

Next I'll need to look at disabling CRCs... although I'm guessing this will need an entirely custom loader.   I want to continue loading despite read errors...
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: db6128 on 10:44, 05 November 12
Quoteakes me wonder why people ever bothered with loading screens 'back in the day'; I guess they used some form of compression, but even so - loading screens must have added valuable minutes to loading times.
It's a valid question in a lot of cases, especially when the screen starts to be longer, or even more enjoyable, than the game itself . . . However, the vast majority of screens that I've seen were not compressed. More clever loading routines might have employed some crunching, but I don't know how common it was.

QuoteNow I have the basics working using standard load/save commands from BASIC, I'd like to experiment with dumping the whole 16k block to tape/disk in one block. I see the CAS_READ and CAS_WRITE ROM routines seem to allow this; I'm guessing as I need to pass values via HL and DE registers I'll need to do this in assembly language - or can I 'poke' the HL and DE registers from BASIC?
You can't control registers from BASIC. You can pass parameters via the CALL command by using the stack, but the only register-mapping that occurs there is to inform the collecting subroutine of the number and address of the data being passed in.

QuoteNext I'll need to look at disabling CRCs... although I'm guessing this will need an entirely custom loader. I want to continue loading despite read errors...
I'm going to try hijacking the standard loading routines just to add the Spectrum-style border. :V That should be fairly easy as I've been practising writing and decoding ASM, including writing somewhat optimised pixel-plotting routines, and I imagine it'll be a fairly simple copy, paste, and addition of some basic I/O [good old confusingly named OUT (C),C].

Since I don't have a CPC with me at the moment, this all has to be done on WinAPE, and so I'll need to go and download tape images... not quite so nostalgic. :D
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: Gryzor on 12:59, 05 November 12
Quote from: TCMSLP
Wow.  I forgot how slow loading from tape was.  Dumping 16k of screen mem to tape takes ~3 minutes.

Makes me wonder why people ever bothered with loading screens 'back in the day';  I guess they used some form of compression, but even so - loading screens must have added valuable minutes to loading times.
I had asked the same thing a while back, I don't think there were any really convincing answers.

But, now that I think of it again, maybe it was a combination of both offering something to the user AND the user ignoring that nothing else happened while the screen was loaded. I'm sure most -if not all- of non-programmer users thought that the program loaded in parallel with the pic or something.

Ultimately, it was a powerful marketing tool - how many companies do you know these days that could have you staring at their logo for five or more minutes?

PS I love the loading sound...
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: Nich on 23:08, 06 November 12
Quote from: Gryzor on 19:35, 04 November 12
Could be that CPCE plays the tape sounds and it conflicts with the actual music?
No, that's not the problem. CPCE plays both the tape loading noises and the music simultaneously, but the tape loading noises are much quieter. Music is played while the main game is loaded into memory (although you need to select "Tape compatibility" mode), so there's no issue with CPCE.

I think the reason why no 'music' is played while the screen is loading is simple; there is no music data embedded in the screen file!

Interestingly, the music on the disc version of Birdie is different to the cassette version. I don't understand why Ere Informatique would do that. ???
Title: Re: Help: Convert, display image, progressive loading (tape)?
Post by: Gryzor on 13:09, 07 November 12
Quote from: NichInterestingly, the music on the disc version of Birdie is different to the cassette version. I don't understand why Ere Informatique would do that.
Well, any number of reasons, the way things were running back then... maybe they didn't have the final version when the first edition went out and they got it later on?
Powered by SMFPacks Menu Editor Mod