Recent

Author Topic: CPC 464 Game Images  (Read 1115 times)

Gigatron

  • Full Member
  • ***
  • Posts: 222
  • Amiga Rulez !!
CPC 464 Game Images
« on: March 09, 2025, 05:29:47 pm »
Hi,

A few weeks ago I had started a project to train on the programming www on Lazarus pascal; The goal is to download for an image on the net and display it. So here is this little project.
Cpc464 was my first computer and i like it ;

The Base web-site is : https://www.cpc-power.com/

You must download this ssl library and put all files to the project drawer:
https://wiki.overbyte.eu/arch/openssl-1.1.1w-win64.zip

** Edit : If I have time the next version will be better, extract the title in the HTML code etc...

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  6.   Spin, BGRAVirtualScreen, BGRABitmap, BGRABitmapTypes, OpenSSLSockets,
  7.   fphttpclient;
  8.  
  9. type
  10.   { TForm1 }
  11.   TForm1 = class(TForm)
  12.     Button1: TButton;
  13.     Label1: TLabel;
  14.     Label2: TLabel;
  15.     Panel1: TPanel;
  16.     SpinEdit1: TSpinEdit;
  17.     SpinEdit2: TSpinEdit;
  18.     VirtualScreen: TBGRAVirtualScreen;
  19.     procedure BGRAVirtualScreenRedraw(Sender: TObject; Bitmap: TBGRABitmap);
  20.     procedure Button1Click(Sender: TObject);
  21.     procedure FormCreate(Sender: TObject);
  22.   private
  23.     FBitmap: TBGRABitmap;
  24.   public
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.   img_num, img_slot, mono: integer;
  30.   HttpClient: TFPHTTPClient;
  31.   MemStream: TMemoryStream;
  32.   ImageURL , ImageWWW : string;
  33.  
  34.  
  35. implementation
  36. {$R *.lfm}
  37.  
  38. { TForm1 }
  39.  
  40. procedure TForm1.FormCreate(Sender: TObject);
  41. begin
  42.   FBitmap  := nil;
  43.   img_num  := SpinEdit1.value;
  44.   img_slot := SpinEdit2.value;
  45.   mono := 1;  // 1 = set ; 0 = unset(color);
  46. end;
  47.  
  48. procedure TForm1.BGRAVirtualScreenRedraw(Sender: TObject; Bitmap: TBGRABitmap);
  49. begin
  50.  
  51.   Bitmap.Fill(BGRAWhite);
  52.   if Assigned(FBitmap) then
  53.   begin
  54.     bitmap.StretchPutImage(rect(0,0,320*2,256*2),Fbitmap,dmSet);
  55.   end;
  56. end;
  57.  
  58. procedure TForm1.Button1Click(Sender: TObject);
  59.  
  60. begin
  61.  
  62.   if Assigned(FBitmap) then
  63.   begin
  64.     FBitmap.Free;
  65.     FBitmap := nil;
  66.   end;
  67.   Imagewww := 'https://www.cpc-power.com/extra_lire_fichier.php?extra=cpcold&fiche=';
  68.   ImageURL := Imagewww+inttostr(img_num)+'&slot='+inttostr(img_slot)+'&part=A&type=.png&green='+inttoStr(mono)+'';
  69.   img_num  := SpinEdit1.value;
  70.   img_slot := SpinEdit2.value;
  71.  
  72.  
  73.   HttpClient := TFPHTTPClient.Create(nil);
  74.   MemStream := TMemoryStream.Create;
  75.  
  76.   try
  77.     try
  78.  
  79.       HttpClient.Get(ImageURL, MemStream);
  80.       MemStream.Position := 0;
  81.       FBitmap := TBGRABitmap.Create(MemStream);
  82.       VirtualScreen.DiscardBitmap;
  83.       VirtualScreen.RedrawBitmap;
  84.     except
  85.       on E: Exception do
  86.         ShowMessage('Erreur de téléchargement: ' + E.Message);
  87.     end;
  88.   finally
  89.     HttpClient.Free;
  90.     MemStream.Free;
  91.   end;
  92.  
  93.   Label1.Caption:= 'Image Number : '+ IntToStr(img_num);
  94.   Label2.Caption:= 'Image Slot : '+ IntToStr(img_slot);
  95.  
  96. end;
  97.  
  98.  
  99. end.
« Last Edit: March 09, 2025, 06:24:20 pm by Gigatron »
Sub Quantum Technology ! Gigatron 68000 Colmar France;

Gigatron

  • Full Member
  • ***
  • Posts: 222
  • Amiga Rulez !!
Re: CPC 464 Game Images
« Reply #1 on: March 10, 2025, 05:28:13 pm »
Hi

This project become interesting, maybe usefull for you.

Added Monochrome color, favorite list , and simple code ;

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  6.   Spin, BGRAVirtualScreen, BGRABitmap, BGRABitmapTypes, OpenSSLSockets,
  7.   fphttpclient, RegExpr;
  8.  
  9. type
  10.   { TForm1 }
  11.   TForm1 = class(TForm)
  12.     Button1: TButton;
  13.     Button2: TButton;
  14.     Button3: TButton;
  15.     Label1: TLabel;
  16.     Label2: TLabel;
  17.     Label3: TLabel;
  18.     ListBox1: TListBox;
  19.     Panel1: TPanel;
  20.     RadioButton1: TRadioButton;
  21.     RadioButton2: TRadioButton;
  22.     SpinEdit1: TSpinEdit;
  23.     SpinEdit2: TSpinEdit;
  24.     VirtualScreen: TBGRAVirtualScreen;
  25.     procedure BGRAVirtualScreenRedraw(Sender: TObject; Bitmap: TBGRABitmap);
  26.     procedure Button1Click(Sender: TObject);
  27.     procedure Button2Click(Sender: TObject);
  28.     procedure Button3Click(Sender: TObject);
  29.     procedure FormCreate(Sender: TObject);
  30.     procedure FormDestroy(Sender: TObject);
  31.     procedure ListBox1SelectionChange(Sender: TObject; User: boolean);
  32.     procedure RadioButton1Change(Sender: TObject);
  33.     procedure RadioButton2Change(Sender: TObject);
  34.   private
  35.     FBitmap: TBGRABitmap;
  36.   public
  37.   end;
  38.  
  39. var
  40.   Form1: TForm1;
  41.   img_num, img_slot, mono: integer;
  42.   HttpClient: TFPHTTPClient;
  43.   MemStream: TMemoryStream;
  44.   ImageURL , ImageWWW,  GameTitle : string;
  45.  
  46. implementation
  47. {$R *.lfm}
  48.  
  49. function GetGameTitle(const URL: string): string;
  50. var
  51.   HttpClient: TFPHTTPClient;
  52.   PageSource: TStringList;
  53.   Regex: TRegExpr;
  54.   RawTitle: string;
  55. begin
  56.   Result := 'Title Not Found ';
  57.   HttpClient := TFPHTTPClient.Create(nil);
  58.   PageSource := TStringList.Create;
  59.   Regex := TRegExpr.Create;
  60.  
  61.   try
  62.     try
  63.       // HTML
  64.       PageSource.Text := HttpClient.Get(URL);
  65.  
  66.       Regex.Expression := '<title>(.*?)</title>';
  67.       if Regex.Exec(PageSource.Text) then
  68.       begin
  69.         RawTitle := Regex.Match[1];
  70.  
  71.         RawTitle := StringReplace(RawTitle, '&copy', ' :', [rfReplaceAll]);
  72.         RawTitle := Trim(RawTitle);
  73.  
  74.         while Pos('  ', RawTitle) > 0 do
  75.           RawTitle := StringReplace(RawTitle, '  ', ' ', [rfReplaceAll]);
  76.  
  77.         Result := UpperCase(RawTitle);
  78.       end;
  79.  
  80.     except
  81.       on E: Exception do
  82.         Result := 'Erreur: ' + E.Message;
  83.     end;
  84.   finally
  85.     HttpClient.Free;
  86.     PageSource.Free;
  87.     Regex.Free;
  88.   end;
  89. end;
  90.  
  91. { TForm1 }
  92.  
  93. procedure TForm1.FormCreate(Sender: TObject);
  94. begin
  95.   FBitmap  := nil;
  96.   img_num  := SpinEdit1.value;
  97.   img_slot := SpinEdit2.value;
  98.   mono := 0;  // 1 = set ; 0 = unset(color);
  99.  
  100.   HttpClient := TFPHTTPClient.Create(nil);
  101.   MemStream := TMemoryStream.Create;
  102.  
  103. end;
  104.  
  105. procedure TForm1.BGRAVirtualScreenRedraw(Sender: TObject; Bitmap: TBGRABitmap);
  106. var
  107.   DestRect: TRect;
  108. begin
  109.   Bitmap.Fill(BGRAWhite);
  110.   if Assigned(FBitmap) then
  111.   begin
  112.     DestRect := Rect(0, 0, VirtualScreen.Width, VirtualScreen.Height);
  113.     Bitmap.StretchPutImage(DestRect, FBitmap, dmSet);
  114.   end;
  115. end;
  116.  
  117. procedure TForm1.Button1Click(Sender: TObject);
  118. var
  119.  PageURL: string;
  120. begin
  121.  
  122.   if Assigned(FBitmap) then  FreeAndNil(FBitmap);
  123.  
  124.   img_num  := SpinEdit1.value;
  125.   img_slot := SpinEdit2.value;
  126.  
  127.   Imagewww := 'https://www.cpc-power.com/extra_lire_fichier.php?extra=cpcold&fiche=';
  128.   ImageURL := Imagewww+inttostr(img_num)+'&slot='+inttostr(img_slot)+'&part=A&type=.png&green='+inttoStr(mono)+'';
  129.  
  130.   PageURL := 'https://www.cpc-power.com/index.php?page=detail&num=' + IntToStr(img_num);
  131.   GameTitle := GetGameTitle(PageURL);
  132.  
  133.   Label3.Caption := '' + GameTitle;
  134.  
  135.   try
  136.   MemStream.Clear;  // Réutilisation du même stream
  137.   HttpClient.Get(ImageURL, MemStream);
  138.   MemStream.Position := 0;
  139.  
  140.  if MemStream.Size > 0 then
  141.   begin
  142.     FBitmap := TBGRABitmap.Create(MemStream);
  143.    // VirtualScreen.DiscardBitmap;
  144.     VirtualScreen.RedrawBitmap;
  145.   end
  146.   else
  147.     ShowMessage('Empty Image ...');
  148.  
  149.   except
  150.   on E: Exception do
  151.     ShowMessage('Loading Error ...' + E.Message);
  152.     end;
  153.  
  154.   Label1.Caption:= 'Game : '+ IntToStr(img_num);
  155.   Label2.Caption:= 'Slot : ' + IntToStr(img_slot);
  156.  
  157. end;
  158. // add to favorite list
  159. procedure TForm1.Button2Click(Sender: TObject);
  160. var
  161.   game_name: String;
  162.   idx: Integer;
  163. begin
  164.  
  165.    idx := Pos(' : ', GameTitle);
  166.    if idx > 0 then
  167.     game_name := Copy(GameTitle, 1, idx - 1)
  168.    else
  169.     game_name := GameTitle;
  170.  
  171.    ListBox1.Items.Add(IntToStr(img_num) + ' : ' + game_name);
  172.  
  173. end;
  174.  
  175. procedure TForm1.Button3Click(Sender: TObject);
  176. begin
  177.   ListBox1.Clear;
  178. end;
  179.  
  180. // get game_num from listbox
  181. procedure TForm1.ListBox1SelectionChange(Sender: TObject; User: boolean);
  182. var
  183.   lst_txt, lst_num : String;
  184.   idx     : integer;
  185. begin
  186.      lst_txt := ListBox1.GetSelectedText;
  187.      idx := Pos(' : ', lst_txt);
  188.      if idx > 0 then
  189.      lst_num := Copy(lst_txt, 1, idx - 1);
  190.  
  191.      SpinEdit1.Value := StrToInt(lst_num);
  192.      ListBox1.Update;
  193.      button1.Click;
  194. end;
  195.  
  196. procedure TForm1.RadioButton1Change(Sender: TObject);
  197. begin
  198.        if RadioButton1.Checked then mono := 1;
  199.        button1.Click;
  200. end;
  201.  
  202. procedure TForm1.RadioButton2Change(Sender: TObject);
  203. begin
  204.       if RadioButton2.Checked then mono := 0;
  205.       button1.Click; // simulate click
  206. end;
  207.  
  208. procedure TForm1.FormDestroy(Sender: TObject);
  209. begin
  210.   FreeAndNil(FBitmap);
  211.   FreeAndNil(HttpClient);
  212.   FreeAndNil(MemStream);
  213. end;
  214.  
  215.  
  216. end.
Sub Quantum Technology ! Gigatron 68000 Colmar France;

Gigatron

  • Full Member
  • ***
  • Posts: 222
  • Amiga Rulez !!
Re: CPC 464 Game Images
« Reply #2 on: March 11, 2025, 01:28:38 am »
Finally with 30 minutes of work this project ends, this shows that with lazarus FPC development is as fast as the speed of light.

You are no need Indylaz , just the ssl library : https://wiki.overbyte.eu/arch/openssl-1.1.1w-win64.zip

Hope you can use this project for other usage.

** Edit
Added all games list , load it and browse cpc games images.

Have Fun
« Last Edit: March 23, 2025, 12:06:56 am by Gigatron »
Sub Quantum Technology ! Gigatron 68000 Colmar France;

Gigatron

  • Full Member
  • ***
  • Posts: 222
  • Amiga Rulez !!
Re: CPC 464 Game Images
« Reply #3 on: March 23, 2025, 08:24:23 pm »
Ok

This project is now finished with some minor change like Find game title in List;
All games list is now included , just unzip and load it;

Have Fun;

« Last Edit: March 23, 2025, 08:30:01 pm by Gigatron »
Sub Quantum Technology ! Gigatron 68000 Colmar France;

 

TinyPortal © 2005-2018