baktra Posted July 10, 2017 Share Posted July 10, 2017 I can see that Mad Pascal's units are getting more procedures and functions that make programming of games easier. This can be a "killer feature". I am also impressed with the inline assembly capabilities. Is there a possibility to create screen code string/character literals? This would allow fast and convenient drawing of strings with the System.Move procedure. Or maybe this can be done with inline assembly... dta d'text' if needed? Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3802796 Share on other sites More sharing options...
TXG/MNX Posted July 17, 2017 Share Posted July 17, 2017 Let make an SDL lib for madpascal Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3807400 Share on other sites More sharing options...
tebe Posted July 30, 2017 Author Share Posted July 30, 2017 (edited) http://mads.atari8.info Mad Pascal 1.5.0 - LONGWORD, DWORD, UINT32, LONGINT - ShortReal (fixed point Q8., Real (fixed point Q24., Single (32bit IEEE-754) - unit SYSTEM (const SINGLE): NaN, Infinity, NegInfinity - unit SYSTEM (type SINGLE): SIN, COS, ABS, SQRT, ISQRT, ROUND, TRUNC - unit MATH (type SINGLE): LOG2, LOG10, LOGN, IsNaN p.s.in attachment compare SINGLE (IEEE-754) versus REAL (Q24.8 fixed-point) p.s. #2 function iSqrt(number: Single): Single; //---------------------------------------------------------------------------------------------- // Fast inverse square root // https://en.wikipedia.org/wiki/Fast_inverse_square_root //---------------------------------------------------------------------------------------------- var sp: ^single; c: cardinal; f0, f1: single; const threehalfs: single = 1.5; begin sp:=@c; f0 := number * 0.5; c := cardinal(number); // evil floating point bit level hacking c := $5f3759df - (c shr 1); // what the fuck? f1 := f0 * sp^ * sp^; Result := sp^ * ( 1.5 - f1 ); // 1st iteration end; single_real.zip Edited July 30, 2017 by tebe 6 Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3816759 Share on other sites More sharing options...
baktra Posted July 30, 2017 Share Posted July 30, 2017 Let make an SDL lib for madpascal Why so simple library. Why not Allegro? Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3816833 Share on other sites More sharing options...
Gury Posted July 31, 2017 Share Posted July 31, 2017 New version, great new additions! Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3817462 Share on other sites More sharing options...
+JAC! Posted July 31, 2017 Share Posted July 31, 2017 c := cardinal(number); // evil floating point bit level hacking c := $5f3759df - (c shr 1); // what the fuck? The final proof that source code comments are a must - best thing is that it's really from Wikipedia . In two weeks I'll a Fujiama, trying out MP for the first time. Englisg Google translation of the docs looks very good. Thanks tebe! 2 Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3817846 Share on other sites More sharing options...
JamesD Posted August 1, 2017 Share Posted August 1, 2017 That's just the magic number used in fast square root implementations.It's simply a constant someone figured out to simplify the formula.I think I ran across the math used to derive it when I was looking at how to implement a fast square root on the MC-10.I also think there was a faster implementation than that. 1 Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3817914 Share on other sites More sharing options...
tebe Posted August 1, 2017 Author Share Posted August 1, 2017 (edited) fast SQRT (IEEE-754 SINGLE) function fsqrt(number: single): single; var sp: ^single; c: cardinal; begin if number < single(0) then exit; sp:=@c; c := cardinal(number) - $3f800000; c := c shr 1; c := c + $3f800000; Result := sp^; Result:=(Result+number/Result) * 0.5; // mul is faster than div Result:=(Result+number/Result) * 0.5; end; original (Hero's algorithm) function Sqrt(x: Single): Single; overload; //---------------------------------------------------------------------------------------------- // Sqrt returns the square root of its argument X, which must be positive //---------------------------------------------------------------------------------------------- var Divisor: Single; begin { Hero's algorithm } if x < single(0) then exit; Result := x; Divisor := 1; while Abs(Result - Divisor) > single(0.0001) do begin Divisor := (Result + Divisor) / 2; Result := x / Divisor; end; end; Edited August 1, 2017 by tebe 2 Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3818101 Share on other sites More sharing options...
pirx Posted August 1, 2017 Share Posted August 1, 2017 Finally one reasonable FP libs on our 8-bitter - no screwing with this wicked 6 byte BCD craze. moving to 4 bytes alone is a gain. They should have stuck to MS Basic I say :] Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3818117 Share on other sites More sharing options...
JamesD Posted August 1, 2017 Share Posted August 1, 2017 (edited) fast SQRT (IEEE-754 SINGLE) function fsqrt(number: single): single; var sp: ^single; c: cardinal; begin if number < single(0) then exit; sp:=@c; c := cardinal(number) - $3f800000; c := c shr 1; c := c + $3f800000; Result := sp^; Result:=(Result+number/Result) * 0.5; // mul is faster than div Result:=(Result+number/Result) * 0.5; end; ... Yeah, that looks more like what I was using. FWIW, Microsoft separates out the sign bit from normal IEEE-754 numbers in their 6803 math library.. They probably did the same thing on other CPUs but I haven't looked. So if any of you ever want to speed up their square root, you need to adjust the magic constant to match. Here is the explanation of the fast SQRT and the magic constant for any of you that care to check it out: http://h14s.p5r.org/2012/09/0x5f3759df.html Just for the record... it's really nice to see a compiler support floating point. I've ported a few BASIC programs to C, and going from floats to int is always a pain in the neck. Edited August 1, 2017 by JamesD 1 Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3818140 Share on other sites More sharing options...
dmsc Posted August 2, 2017 Share Posted August 2, 2017 Hi! http://mads.atari8.info Mad Pascal 1.5.0 - LONGWORD, DWORD, UINT32, LONGINT - ShortReal (fixed point Q8., Real (fixed point Q24., Single (32bit IEEE-754) - unit SYSTEM (const SINGLE): NaN, Infinity, NegInfinity - unit SYSTEM (type SINGLE): SIN, COS, ABS, SQRT, ISQRT, ROUND, TRUNC - unit MATH (type SINGLE): LOG2, LOG10, LOGN, IsNaN This is great! I looked at your math functions, I think that there are various optimizations possible. For now, this is a sine/cosine routines that are shorter and faster than the current ones, using a polynomial approximation to the full [0,pi/2] range. function fsincos(x: single; sc: boolean): single; var i: byte; begin { Normalize argument, divide by (pi/2) } x := x * 0.63661977236758134308; { Get's integer part, should be } i := trunc(x); { Fixes negative part, needed to calculate "fractional" part } if cardinal(x) >= $80000000 then { this is shorter than "x < 0" } dec(i); { And finally get's fractional part } x := x - single(shortint(i)); { If we need cosine, adds pi/2 } if sc then inc(i); { Test quadrant, odd values are reflected } if (i and 1) = 0 then x := single(1) - x; { Calculate cosine(x) with optimal polynomial approximation } x := x * x; Result := (((0.019940292 - x * 0.00084688153) * x - 0.23369547) * x + 1) * (1-x); { Test quadrant to return negative values } if (i and 2) = 2 then Result := -Result; end; function fsin(x: single): single; begin Result := fsincos(x, false); end; function fcos(x: single): single; begin Result := fsincos(x, true); end; The first function calculates sine or cosine depending on the value of "sc", true for cosine, false for sine. The functions bellow calls the main one with the correct argument. With the given polynomial the functions have a maximal relative error of 3.77777e-07, so the real limit is the normalization by (pi/2) at the start, as the division is not as accurate with large arguments. Note that if you add one term to the polynomial, the function can be made accurate to the full IEEE754 precision, but of course will be slower and bigger. Finally one reasonable FP libs on our 8-bitter - no screwing with this wicked 6 byte BCD craze. moving to 4 bytes alone is a gain. They should have stuck to MS Basic I say :] I agree, but i recognize that for a lot of people BCD math was the correct choice, as very few understand why "0.1" is not an exact FP number, and why "FOR I=0 to 3 STEP 0.01" does not end with I=3. Yeah, that looks more like what I was using. FWIW, Microsoft separates out the sign bit from normal IEEE-754 numbers in their 6803 math library.. They probably did the same thing on other CPUs but I haven't looked. So if any of you ever want to speed up their square root, you need to adjust the magic constant to match. Here is the explanation of the fast SQRT and the magic constant for any of you that care to check it out: http://h14s.p5r.org/2012/09/0x5f3759df.html Just for the record... it's really nice to see a compiler support floating point. I've ported a few BASIC programs to C, and going from floats to int is always a pain in the neck. Yes, in 8bit implementations it's normal to modify the IEEE754 format to remove the need to pack/unpack the numbers on each operation, see http://ww1.microchip.com/downloads/en/AppNotes/00575.pdffor a modern FP library in an 8bit micro, this uses the trick to exchange the position of the sign bit. Also of interest are the accompanying functions at http://ww1.microchip.com/downloads/en/AppNotes/00660.pdf , porting some of the functions to 6502 assembly is not that difficult. 2 Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3818764 Share on other sites More sharing options...
tebe Posted August 2, 2017 Author Share Posted August 2, 2017 thx DMSC, it's a big acceleration Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3818803 Share on other sites More sharing options...
+JAC! Posted August 18, 2017 Share Posted August 18, 2017 I am trying to convert an ACTION! program to MP. In ACTION you can decare variables like labels in assembler, i.e. you define the name, type and memory location. This way you can have BYTE ROWCRS=$54 ... ROWCRS = 0 becomes LDA #0:STA $54. How would I translate this to MP? ;OS ADDRESSES: PAGE 0BYTE ROWCRS=$54BYTE COLCRS=$55CARD SAVMSC=$58BYTE RAMTOP=$6A ;OS ADDRESSES: PAGE 2BYTE SDMCTL=$22FBYTE SDLSTL=$230BYTE TXTROW=$290CARD TXTCOL=$291BYTE COLOR1=709BYTE COLOR2=710BYTE CURINH=755BYTE CHBAS=756BYTE CH=764 ; GTIA REGISTERSBYTE CONSOL=53279; ACTION VARIABLESCARD STANDARD_ERRORCARD BLOAD_ERRORBYTE BLOAD_DONE PROC CIOV2=$E456(BYTE AREG,XREG) Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3829768 Share on other sites More sharing options...
Gury Posted August 18, 2017 Share Posted August 18, 2017 Hi, In Mad Pascal you can do this, for example: var CHBAS : byte absolute $2F4; Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3829774 Share on other sites More sharing options...
+JAC! Posted August 18, 2017 Share Posted August 18, 2017 Thanks, had found that in the examples also meanwhile. Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3830023 Share on other sites More sharing options...
tebe Posted August 19, 2017 Author Share Posted August 19, 2017 http://www.ousob.com/ng/pascal/ng4c43.php Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3830704 Share on other sites More sharing options...
gozar Posted August 20, 2017 Share Posted August 20, 2017 [blockquote]More than one variable can be declared at any given address.[/blockquote] That's gotta make debugging fun. Sent from my iPhone using Tapatalk 1 Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3830834 Share on other sites More sharing options...
+David_P Posted August 20, 2017 Share Posted August 20, 2017 Actually, for some hardware registers there are different functions for read vs write, so having two names makes debugging easier. 2 Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3830897 Share on other sites More sharing options...
peteym5 Posted August 23, 2017 Share Posted August 23, 2017 I really want to move onto using Mad Pascal for future games I intend to market on cartridge. It will be much easier than trying to do huge programs all in assembly. I probably limit it to games that fit inside 16K for starters as doing any type of bank switching will add another problem to deal with. From what I done so far, it looks like it has a lot of potential. Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3833255 Share on other sites More sharing options...
Gury Posted August 26, 2017 Share Posted August 26, 2017 (edited) I am just wondering what's the deal with using memory address at a000 (left slot cartridge ROM, Atari BASIC area) in Mad Pascal. Are there any conflicts in using this area, I mean, filling this area directly with some data and not interfering with any of routines in Mad Pascal library? Good examples of using this area are nuts.pas, plasma.pas and music players. We know that we gain 16K of additional memory this way, not used in traditional way. So I wonder if I have to set any additional routines before using this area? I didn't find code for switching off Atari BASIC in these examples. What am I missing? Edited August 26, 2017 by Gury Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3834978 Share on other sites More sharing options...
bocianu Posted August 26, 2017 Share Posted August 26, 2017 I think there is no problem using memory above A000. You can take a look into sources of PacMad, I'm switching off OS (procedure SystemOff), taking over vblank, and using all memory above A000 (except D000-D800). In MadPascal examples, system is also switched off in 'pasintro'. Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3835054 Share on other sites More sharing options...
+JAC! Posted August 27, 2017 Share Posted August 27, 2017 Now I'm stuck for the first time: type tile = record ts,tr,tx,ty,tz: byte end;var tile_map: array[0..0] of byte absolute $414; // TODO Actual size? procedure init_tiles; var shape_list: array[0..6] of byte = (1, 1, 2, 3, 3, 4, 5); var t: ^tile; var i: byte; t:=tile_map; // Yields: Syntax error, ':' expected but ':=' found t:=@tile_map[0]; // Yields: Syntax error, ':' expected but ':=' found Any ideas? EDIT: Found it. The BEGIN was missing after the VAR block. 1 Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3835720 Share on other sites More sharing options...
+JAC! Posted August 27, 2017 Share Posted August 27, 2017 Next: I have an array of records in memory. // 8 tilestype tile = record ts,tr,tx,ty,tz: byte end;const tile_count = 8;const tile_size = SizeOf(tile);const tile_map_size = tile_count*tile_size; var tile_map array[0..tile_count-1] of tile absolute $414; Yields: Error: Multidimensional arrays are not supported Does it mean arrays of recording not (yet) supported? When I try to use pointers instead, I get: var tile_map: ^tile; procedure test;var tile_map2: ^tile;begin tile_map2 := tile_map; // Incompatible types: got "RECORD" expected "POINTER"end; Why? Both sides are ^tile? Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3835762 Share on other sites More sharing options...
tebe Posted August 28, 2017 Author Share Posted August 28, 2017 (edited) JAC!, 'sprites.inc' from PacMad sprites.zip Edited August 28, 2017 by tebe Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3836443 Share on other sites More sharing options...
+JAC! Posted August 29, 2017 Share Posted August 29, 2017 Thanks, I see arrays of records are not supported and I'll use arrays of pointers to records. That is fine. Maybe you can make the error message a litte more explicit. But the 2nd problem I don't unterstand. What is wrong with the assignment of two variables of the same type (here ^tile)? Addition: var tile_map: array[0..tile_count-1] of pointer; // accepted type tile = record ts,tr,tx,ty,tz: byte end;type ptile = ^tile; var tile_map: array[0..tile_count-1] of ptile; // Error: Multidimensional arrays are not supported So no typed arrays of pointer? Quote Link to comment https://forums.atariage.com/topic/240919-mad-pascal/page/10/#findComment-3836845 Share on other sites More sharing options...
Recommended Posts
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.