New version of init a restore rout for GFA demo / game

GFA BASIC-related articles in here please

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
hylst
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 133
Joined: Wed Apr 27, 2011 6:22 pm
Location: France : Strasbourg
Contact:

New version of init a restore rout for GFA demo / game

Postby hylst » Wed Oct 30, 2013 3:35 pm

Hello. I'm still trying to optimyze and before all avoid memory waste and bombs when compiling my programs.
All my previous demo screen for Japemo work... but do not restore that well the system after while using this procedures.
I wanted to load from a game main menu for this megademo other screens, but i missed so many times...

Could you help me with it, see what could be the best ?

procedure hello to initialize most thing for the program
procedure bye to restore the system as before.

I assume we are working at least on a 1040 St(f/e) .

Do we really need to use reserve if we use malloc before for the same spece ?

IF FRE()>800000
RESERVE FRE()
mem%=malloc(800000) ! if 800 000 is the amount of memory we really need for trhe proggy
ELSE
EDIT
ENDIF

Should be ok or just space%=malloc(800000) would be enough (with $m 800000 compiler option notified)

Code: Select all

hello
BLOAD "DATA.DAT",mem%      ! Load data to mem% (max. 800000 bytes)
' DO THINGS
bye
VOID MFREE(start%)                !Set memory free
RESERVE   
PROCEDURE hello
' compiler options
  $m800000 ! memory need for the program 2 be compiled - OR RESERVE...
  ' $I- ! disable interrupt routine  -  $I+{ would enable them
  ' $N- ! Disable FOR-NEXT range checking
  ' $S> ! Fast select case  -  $C< slower but shorter code
  ' $*& ! Longword multiplication with muls  -  $*% :  without
  ' $%3 ! Always execute integer division as an integer division  -   $%0 = opposite
  '
  '  ~GRAF_MOUSE(256,0) ! =OUT 4,18 hide mouse (hidem don't work with patched libs)
  OUT 4,18
  sup%=GEMDOS(32,L:0) ! super
  compiled!=BYTE{BASEPAGE+256}<>96  ! false=interpreted/true=compiled
  IF NOT compiled!
   IF FRE()<800000
         RESERVE 800000 ! reserve 800 000 byte if we need that for the program if run under interpreter
   ELSE
          ~GEMDOS(32,L:sup%)
          EDIT
  ENDIF
  ENDIF
  oldrez&=XBIOS(4)  ! save reso
  oldlog%=XBIOS(3) ! save logical screen adress
  oldphy%=XBIOS(2) ! save logical screen adress
  screen%=MALLOC(32255) ! reserve memory for double screen buffer, only other malloc withj main mem% malloc because errors often occurs while too many malloc are done
  IF screen%<=0
    ~GEMDOS(32,L:sup%)
    IF NOT compiled!
      RESERVE
    ENDIF
    EDIT
  ENDIF
  mem%=malloc(800000) ! i assume ther is 800 000 bytes available   buffer to use for every thing, gfx, music, various data, to use use with relativ adresse variables later to be clear
  log%=(screen%+255) AND &HFFFFFF00 ! Stf compatible adress for video shifter
  phy%=oldphy%
  ~XBIOS(5,L:phy%,L:log%,W:0) ! set the screens at these new adresses
  BMOVE phy%,log%,32000  ! clear new screens
  a|=BYTE{&HFF820D}   ! ste test
  BYTE{&HFF820D}=15
  b|=BYTE{&HFF820D}
  BYTE{&HFF820D}=a|
  IF a|<>b|  ! If Ste or Falcon (not STf not TT)
    blitter(TRUE)
  ENDIF
  DIM oldpal&(16)   ! should i avoid arrays and prefer several malloc ?
  BMOVE &HFFFF8240,V:oldpal&(0),32
  DIM stzpal&(16)
  ARRAYFILL stzpal&(),0
  stzpal%=V:stzpal&(0)
  DIM currentpal&(16)
  pal%=V:currentpal&(0)
  key|=BYTE{&H484}         ! save keyboard
  inter|=BYTE{&HFFFA09}    ! save interrupts
  BYTE{&H484}=BYTE{&H484} AND &HFE ! keyboard sound off
  ' BYTE{&H484}=0            ! keyboard off
  CLIP 0,0,320,200 ! required for patched libs otherwise gfx are not visible
  ON ERROR GOSUB bye ! hope this doesn't slow program
  ON BREAK GOSUB bye ! to avoid disagreements in case...
RETURN
> PROCEDURE bye
  ' ~MFREE(screen%) ! free screen buffer, not necessary at the end of the program : automatic according to Lonny
  ' ~MFREE(mem%)   ! free screen buffer, not necessary at the end of the program : automatic according to Lonny
  ~XBIOS(5,L:oldphy%,L:oldlog%,oldrez&) ! back to old screens & reso
  ~XBIOS(6,L:V:oldpal&(0)) ! restore pal
  BYTE{&H484}=key|    ! restore keyboard
  BYTE{&HFFFA09}=inter|  !  restore interrupts
  IF DIM?(regsndh%())    ! stop soundchip
    RCALL sndhplay%+28+4,regsndh%()
  ENDIF
  {&H4D2}=0  ! music off
  WAVE 0,0   ! sound off
  ~GEMDOS(32,L:sup%) ! user mode on
  ' ~GRAF_MOUSE(257,0) ! =OUT 4,8 show mouse (showm don't work with patched libs)
  OUT 4,8
  IF NOT compiled!
    RESERVE
  ENDIF
  EDIT
RETURN
Falcon CT60 +CENTRAM14 - 520 STE 4M - 1040 STf
Let's visit my Personal website http://hylst.t15.org !
The new website of my productions (French for the moment)

User avatar
hylst
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 133
Joined: Wed Apr 27, 2011 6:22 pm
Location: France : Strasbourg
Contact:

Re: New version of init a restore rout for GFA demo / game

Postby hylst » Sat Nov 02, 2013 3:23 pm

Ok ... no answer..

Well never mind, i can imagine that kind of GFA doesn't interest much people.

I talked with Lonny, so, Reserve is only for strings and arrays (and variables) (dc.b ds.l. ...). Malloc is not dependant with reserve.
No need to mfree at the end.

I'll test ...
Falcon CT60 +CENTRAM14 - 520 STE 4M - 1040 STf
Let's visit my Personal website http://hylst.t15.org !
The new website of my productions (French for the moment)

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2257
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: New version of init a restore rout for GFA demo / game

Postby lp » Sat Nov 02, 2013 3:58 pm

I missed this thread somehow. I should clarify one point about mfree().

If compiled its true, you don't need to do it, because when an app terminates gemdos automatically frees all the ram associated with the program at pterm().

However, if testing in the editor you do need to call mfree() or each RUN of the program will eat more an more ram.
I would suggest either always use mfree(), or put mfree() inside the IF compiled! ENDIF at exit. When a program in the editor ends, it does not pterm(), it returns control back to the editor. :wink:

Another idea is to malloc() all your ram in one big chunk, and sub-divide it into blocks yourself, this way you only need one mfree().

Code: Select all

' something like this
ramsize%=32000 !screen 1
add ramsize%,32000 !screen 2
ptr%=malloc(ramsize%)
if ptr%<=0
  ' failed!
endif
screen1%=ptr%
screen2%=ptr%+32000
' lots of code
~mfree(ptr%)

User avatar
hylst
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 133
Joined: Wed Apr 27, 2011 6:22 pm
Location: France : Strasbourg
Contact:

Re: New version of init a restore rout for GFA demo / game

Postby hylst » Sun Nov 03, 2013 12:23 pm

That's it !

Thank you for your help Lonny :)
Falcon CT60 +CENTRAM14 - 520 STE 4M - 1040 STf
Let's visit my Personal website http://hylst.t15.org !
The new website of my productions (French for the moment)

FedePede04
Atari Super Hero
Atari Super Hero
Posts: 951
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: New version of init a restore rout for GFA demo / game

Postby FedePede04 » Sun Nov 03, 2013 1:07 pm

Hi Hylst
sorry that i can not help you with you problem, it is over 25 years that i touched GFA Basic. :lol:

I just like to say that i like your other GFA demos you upload to YouTube,
so i hope it's for something new :cheers:
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2257
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: New version of init a restore rout for GFA demo / game

Postby lp » Sun Nov 03, 2013 2:56 pm

hylst wrote:That's it !

Thank you for your help Lonny :)


I could not see your code during our facebook chat, but when I found it here, it was easier to see what you were doing. :)

User avatar
hylst
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 133
Joined: Wed Apr 27, 2011 6:22 pm
Location: France : Strasbourg
Contact:

Re: New version of init a restore rout for GFA demo / game

Postby hylst » Tue Apr 01, 2014 3:04 pm

FedePede04 wrote:Hi Hylst
sorry that i can not help you with you problem, it is over 25 years that i touched GFA Basic. :lol:

I just like to say that i like your other GFA demos you upload to YouTube,
so i hope it's for something new :cheers:


Glad you think so :)
Thanks !
Falcon CT60 +CENTRAM14 - 520 STE 4M - 1040 STf
Let's visit my Personal website http://hylst.t15.org !
The new website of my productions (French for the moment)


Social Media

     

Return to “GFA BASIC”

Who is online

Users browsing this forum: No registered users and 1 guest

cron