1

How to use C to read rom data to ram ? And how to set block address ? So strange that ROM low address is connect to a counter not from CPU address. So, must have do something that can set address and read from the rom cart. Please help. Thanks.

2

Read this before : topics/52655-tuto-utiliser-des-fichiers-externes-dans-vos-programmes-lynx

if you don't understand french, say us.
avatar
Webmaster du site Ti-FRv3 (et aussi de DevLynx)
Si moins de monde enculait le système, alors celui ci aurait plus de mal à nous sortir de si grosses merdes !
"L'erreur humaine est humaine"©Nil (2006) // topics/6238-moved-jamais-jaurais-pense-faire-ca

3

Yes, I don't understand french. I come from Hong Kong. If you're kind enough, can you translate it to english doc ? Then other people like me can understand it. Also, do you know when Lynx reset, what it will do ?? I think it must load data from rom cart to main ram address to run ? if yes, where will be that ram address ? And it will load from rom cart byte $0000 first ? Sorry, too many question. Many thing I don't sure and want to know. Thank you.

4

Fadest :
Comme vous le savez, la ram de la Lynx fait 64ko, donc cotre programme ne peut pas dépasser cette taille.
As you probably know, Lyn Ram is 64ko wide, (as on each 8 bit system) So the program musn't be wider than this

Ce qui est très limitatif une fois linké les sprites, fonds, sons...
It quickly becomes a problem, regarding to sprite size, backgrounds, sounds...

Pourtant, une cartouche Lynx fait 256ko en moyenne.
But as you can have read on the link in the other thread, Rom (cart) size can be 64ko to a maximum of 1Mo, with 256ko of average size in most of comercial lynx games

Vous pouvez donc choisir de faire une compil en mettant plusieurs jeux sur le même cartouche, ou ajouter les datas en externes et les charger en mémoire vive.
You can chose to make a "compilation" of some games on the same cartdrige, or to add external data and then loading them into RAM

Malheureusement, les fonctions de gestion des fichiers ne sont pas terminées dans le kit BLL (à priori, le source ASM existe dans les librairies, mais elles ne sont pas disponibles pour els développement C car pas finalisées), mais il est possible de se débrouiller en faisant des lectures par blocs.
Unfortunately, file management functions in the BLL kit (the ASM source is available in libraries but C header aren't provided). But it's possible to manage using this feature reading by blocs.

C'est ce point que nous allons aborder maintenant :
Tout d'abord le source C
Let's have a see to the C source code cheeky


#include <stdlib.h>
#include <lynx.h>
#include <lynxlib.h>
#include "titre.pal"

/* LYNX-specific #defines: */
#define BUTTON_OUTER	0x01

extern char FileEntry[8]; 
/*_FileEntry : struct of 8 bytes
FileStartBlock  ds 1
FileBlockOffset ds 2
FileExecFlag    ds 1
FileDestAddr    ds 2
FileFileLen     ds 2
*/
char titre[2048];
char musak[35000];

char SCREEN[8160]       at (0xfff8-16320); // screen 1

extern char SCB1[];
#asm         
_SCB1     dc.b $c7,$10,$20
          dc.w 0,0
          dc.w 0,0,$100,$100
          ; Because we didn't use -C when calling SPRPCK we can
          ; use the same colour palette indexes for all tiles
          dc.b $01,$23,$45,$67,$89,$Ab,$cd,$ef
#endasm

/*********************/
/* wait for a button */
/*********************/
char WaitButton()
{
   char key;
   while (joystick);
   while ( (key = joystick) != BUTTON_OUTER)      ;
   /* wait for the button to be released */
   while ( joystick )      ;
   return key;
}


/**************************************************************************
**                                                                       **
**                                                                       **
**************************************************************************/
main() 
{
char i;

  InitIRQ();
  CLI;

  SetBuffers(SCREEN, 0,0);

  SmpInit(0,1);
  EnableIRQ(1);

  /* set the palette */
  SetRGB(pal);

  LoadCartDir(2);
  DrawFBox(0,0,160,102,i);
  LoadCartBlock(FileEntry[0], titre);
  LoadCartBlock(FileEntry[0]+1, titre+1024);
  SCBDATA(SCB1) = titre;
  DrawSprite(SCB1);
  WaitButton();

  LoadCartDir(5);
  for (i=0; i<33; i++)
     LoadCartBlock(FileEntry[0]+i, musak+i*1024);

  SmpStart(musak,0);

  for( ; ; );
}


Le programme est compilé, assemblé et liké, on obtient un fichier test.o
once compiled & assembled, the program gives us a TEST.O file


Il faut ensuite créer une image Lynx avec le programme LYNXER
Then use the LYNXER utility to make an Lynx image


Pour celà, on crée un fichier test.mak et on appelle la commande LYNXER test.mak
Contenu de test.mak :
To do so, we must create a TEST.MAK file and then call the Lynxer command with test.mak as argument


INSERT.O
test.o
#ALIGN 
fond.spr
#ALIGN 
ti002000.spr
#ALIGN 
ti003000.spr
#ALIGN
test.lsf

insert.o = traitement d'init de la lynx
init of the lynx system (boot code)

test.o = notre programme
our program

Ensuite, il s'agit des fichiers à inclure, soit :
Then files to include

fond.spr
ti00200.spr
ti003000.spr : 3 sprites 160x102 dans ce cas (gérénés par sprpck sans préciser l'option -p0)
3 160*102 sprites, generated with sprpck WITHOUT specifying the -p0 option

test.lsf : un sample généré par wav2lsf (voir tuto sonorisez votre lynx)
A sound sample, made with WAV2LSF.EXE


Pour simplifier la gestion, les fichiers sont alignés sur le début d'un bloc grâce à la commande #ALIGN à mettre sur la ligne précédente.
Each file is bloc aligned with the #ALIGN command on each previous lign


On obtient un fichier test.lyx à flasher sur cartouche.
We have a TEST.LYX ready to be used on the cartdrige


Pour tester avec Handy, il faut le transformer en image avec make_lnx test.lyx -b0 256k
If you prefer Testing with HANDY emulator, you have to make an handy image calling MAKE_LNX TEST.LYX -b0 256k


Bon, maintenant, l'explication du programme :
So now how does it works ? cheeky


On définit donc 2 espaces mémoire titre (un sprite 160x102 prend 2048 octets) et musak (taille en fonction du fichier .lsf).
We define two empty spaces for the title

Chargement et affichage du fond :
Loading & displaying background sprite

  LoadCartDir(2);
  LoadCartBlock(FileEntry[0], titre);
  LoadCartBlock(FileEntry[0]+1, titre+1024);
  SCBDATA(SCB1) = titre;
  DrawSprite(SCB1);

LoadCartDir permet d'initialiser le tableau FileEntry pour le fichier passé en paramètre (ici 2, donc fond.spr)
LoadCartDir allows Filentry table initialisation for the file that is passed (here 2, so FOND.SPR)


FileEntry[ 0] contient le n° de bloc contenant le début du fichier, comme on a spécifié #ALIGN, on sait que le fichier débute en début de bloc.
FileEntry[0] contain the bloc number containing the start of th file, and because we specified #ALIGN, we know that the files start a the begining of the bloc


LoadCartBlock charge 1 bloc de 1024 octets spécifié en premier paramètre à l'adresse donnée dans le deuxième paramètre.
LoadCartBlock loads a 1024 Bytes bloc specified as first parameter at the adress given as second parameter

Comme un sprite fond fait 2 blocs, on duplique LoadCartBlock (chargement du bloc suivant 1024 octets plus loin dans titre)
As a background sprite has a size of 2 blocs, we call LoadCartBlock twice

Ensuite, on affiche le sprite
Then display of the sprite

Pour le sample, chez moi, il fait 33 ko, donc au lieu de dupliquer 33 fois LoadCartBlock, j'ai fait une boucle, mais le principe est le même :
My sound sample is 33ko, so instead of calling 33 times LoadCartBlock, I've made a loop, but the functionment is the same

  LoadCartDir(5);
  for (i=0; i<33; i++)
     LoadCartBlock(FileEntry[0]+i, musak+i*1024);

  SmpStart(musak,0);

Une fois musak chargée, il suffit de la jouer.
As soon as the NOISE cheeky is loaded, we only have to play it.

Voilà, c'est rapide et nouveau pour moi, mais je pense que ça peut être utile à quelqu'un.
et si vous avez des questions ou des précisions à apporter, n'hésitez pas.

So it's a quick translation, if you need more details, don't Hesitate


POUR TOUS LES AUTRES, ON CONTINUE EN ANGLAIS
(we continue in english in your threads wink)
avatar
Webmaster du site Ti-FRv3 (et aussi de DevLynx)
Si moins de monde enculait le système, alors celui ci aurait plus de mal à nous sortir de si grosses merdes !
"L'erreur humaine est humaine"©Nil (2006) // topics/6238-moved-jamais-jaurais-pense-faire-ca

5

Thanks Vince, this is great help ! I'll start to learn it. But do you know where to download this whole package ? because some file mention there have fond.spr , ti002000.spr , ti003000.spr and test.lsf . Where to get ? I want to compile it and test. Thanks.

6

Hello Tomywong and welcome,
Great to see there are lynx fans in HongKong, and better, Lynx fans who are interested in development.

Yes, I know I should have put a package with the whole objects, but I wasn't on my computer when I posted this (and I'm still not).
You can rebuild *.spr files with SPRPCK tool.
fond.spr is a 160x102 16colors BMP converted like this :
SPRPCK -t6 -S160102 -r001001 fond.bmp

ti002000.spr and ti003000.spr are not used. I just linked them to show that you can access every file you want with LoadCartDir(n). So I put 2 useless file in the Rom... You can put 3 times fond.spr if you want.
For test.lsf, you will need a .wav file (8 bits mono, 8khz) and convert it to Lynx Sound Format with wav2lsf like this :
wav2lsf test.wav -o test.lsf

Here is a link where you will find wav2lsf : http://fadest.free.fr/DevLynx/tutowav.zip (I hope the zip file is correct)

Be careful, my lsf file is 33 ko long, so I did a loop :
for (i=0; i<33; i++)
LoadCartBlock(FileEntry[0]+i, musak+i*1024);

You will have to adjust your for loop to the size of your file.

Hope this is clear, I will try to make a package tonight at home...

avatar
De nouveaux jeux pour vos vieilles consoles ? En 2024 ?
https://yastuna-games.com

7

Thank you Fadest !!
Do you have wav2lsf.zip ? It original come from here : http://www.monlynx.de/lynx/tools.html
But it has broken link. From this site, it say it come with sample packer. And I don't know wav2lsf.zip is come with source or not. If yes, I also want to get.
Because from your tutowav.zip, it only have wav2lsf binaries. Thank you.
I also have another question for you. Do you know what Lynx will do when power on ? Do it load from rom first byte to main memory $xxxx, then jump to there ?
Thanks

8

9

Thank you for all people helping !

10

Hello Tomywong, and welcome in the great world of lynx programming grin
---------------------------------
Cooper / Paradize
STf/Mega ST/STe/F030/Lynx
---------------------------------
mes prods lynx : http://atarithemes.chez-alice.fr/lynx/index.php
mes prods ST/Falcon : http://paradize.atari.org