Jump to content

Recommended Posts

Posted (edited)
5 hours ago, Gury said:

Variables using Type declaration

 

I found a strange behaviour when using type variable (array of type). Let's explain...

 

I increment a type variable element by some value:

 

monster[0].x := monster[0].x + 2;

 

This code runs ok.

 

But using a procedure, which consists of incrementing such variable, doesn't work correctly.

The example works when commenting (remarking) the call to MoveMonster at the end of listing example.

 

This is modified example from Mad Pascal repository:


uses crt;

type
	monsters = packed record
   	  x: byte ;
	  a: cardinal;
	  y: byte;
	end;

var
	monster: array [0..3] of ^monsters;
	i: byte;

procedure MoveMonster(p : byte);
begin
  monster[p].x := monster[p].x + 2;
end;

begin
  for i:=0 to High(monster) do begin
    GetMem(monster[i], sizeof(monsters));

    monster[i].x := i;
    monster[i].a := $ffffffff;
    monster[i].y := i * 2;
  end;

  for i:=0 to High(monster) do
    writeln(monster[i].x,',', monster[i].y);

  // Let's move first monster
  writeln('');
  writeln('Let''s move first monster');
//  monster[0].x := 2;
  monster[0].x := monster[0].x + 2;
  writeln(monster[0].x,',', monster[0].y);

  MoveMonster(0);
  writeln(monster[0].x,',', monster[0].y);

  repeat until keypressed;
end.

 

 

bug fixed, https://github.com/tebe6502/Mad-Pascal  (master branch)

fix.png

Edited by tebe
  • Thanks 2

Share this post


Link to post
Share on other sites

With such great support and addons my monsters decided not to be agressive too much. They just want some beer and conversation in good ambient to avoid hot sun.

 

  • Haha 1

Share this post


Link to post
Share on other sites
Posted (edited)

Github, master branch

 

new feature, variable as REGISTER (utilized zero page, 16 bytes)

 

var

 a: byte register;
 b: word register;

 

be careful, the compiler also uses these areas (Fillchar, Fillbyte, Move)

    

Edited by tebe
  • Thanks 1

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Wow, this is the first time I see the new github style documentation. That is really awesome and good to read! The support for the players and modules as resource is also great.

I tried to click the "edit on github" button to report a minor fix: "null side" instead of "zero page". But the link results in "404 - https://github.com/tebe6502/Mad-Pascal/edit/master/docs/map.md".
Might of course be due to not being part of the repo... 

Share this post


Link to post
Share on other sites

Great language and documentation. This makes Mad Pascal even stronger, there is no match for it.

 

  • Like 4

Share this post


Link to post
Share on other sites

Hi,

i'd like to create an array of records, like this:

Quote

type
    tNPC =  record ai,x,y,z: array [0..2] of byte;
                           t: array [0..3] of byte;
                           person: byte;
                           dialog: byte
    end;
     

var 
    npc: array [0..7] of tNPC;

 

which MP says it does not support:

Quote

Mad Pascal Compiler version 1.6.6 [2021/09/19] for 6502
Compiling City.pas
City.pas (33,25) Error: Only Array [0..2] of ^RECORD supported

maybe i'm missing something basic in pascal; but i couldn't figure out yet how to create an alternative datastructure that would be as easy to access and manipulate like with the example above ? ( like:  write(npc[0].x[1]); )

 

--> sorry: yes, i missed something basic: question solved by reading this very thread:

 

-->  npc: array [0..2] of ^tNPC;
 

just that nested arrays of records don't seem to be accessible?

 

write(npc[0].person);  -> ok

write(npc[0].x[0]);      -> Error: Can't read or write variables of this type

 

Edited by Atlan_Roland
question rephrased.

Share this post


Link to post
Share on other sites
17 hours ago, tebe said:

 

hmm, just tried the example for for/in/do with your latest github master branch mp.exe.  is the code not in yet?

program for_in_do;
 var
    days : array [0..6] of string =
    ('poniedzialek', 'wtorek', 'sroda' ,'czwartek', 'piatek', 'sobota', 'niedziela');
    a: string;

begin
	for a in days do 
		writeln(a);
end.

Mad Pascal Compiler version 1.6.6 [2021/10/08] for 6502
Compiling pathfinder.pas
pathfinder.pas (8,6) Error: Ordinal variable expected as 'FOR' loop counter

Share this post


Link to post
Share on other sites

MP.EXE file was not up-to-date, files in SRC directory were updated 

 

now it has been corrected 

  • Like 2

Share this post


Link to post
Share on other sites

Example of macro in MP


{$define plot(x) := scrn [x] := lookupMul[xbuf1[x] + tmp] + lookupDiv[xbuf0[x] + tmp]}

mp_macro.7z

  • Like 2
  • Thanks 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...