GFA
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
Le Deal du moment : -45%
WHIRLPOOL OWFC3C26X – Lave-vaisselle pose libre ...
Voir le deal
339 €

Routines d’initialisation et restauration pour jeu et demos

Aller en bas

Routines d’initialisation et restauration pour jeu et demos Empty Routines d’initialisation et restauration pour jeu et demos

Message par Shadow272 Sam 21 Nov - 15:12

Routines d’initialisation et restauration pour jeu et demos
Par hylst

Prévue pour une résolution ST basse et accompagnée de quelques procédures utiles telle que des fondu de couleur, la stabilisation d'écran, la conversion de couleur vdi, attente touche, efface palette, aide au debug, ...
J'ai essayé de la faire plutôt complète, mais si vous voyez des choses à corriger ou des erreurs..

[Vous devez être inscrit et connecté pour voir ce lien] :

Code:

' Initialisation and utils for GFA demo and games on ATARI ST in low res
' Big thanks to Lonny Pursell for all his help on compiling
' Hylst - v1.6 - 06/2011
'
hello ! general init
'
'
' Demo / Game time !
'
'
bye ! restore everything
'
> PROCEDURE hello
  ' compiler options
  ' $m500000 ! 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
  '
  RESERVE 500000 ! if run under interpreter
  oldrez&=XBIOS(4)  ! save reso
  oldlog%=XBIOS(3) ! save logical screen adress
  oldphy%=XBIOS(2) ! save logical screen adress
  screen1%=MALLOC(32255) ! reserve memory for double screen buffer
  screen2%=MALLOC(32255) ! to prevent blinking
  log%=(screen1%+255) AND &HFFFFFF00 ! Stf compatible adress for video shifter
  phy%=(screen2%+255) AND &HFFFFFF00
  ~XBIOS(5,L:phy%,L:log%,W:0) ! set the screens at these new adresses
  CLS  ! 0 low reso  1 medium  2 high  3 reserved 4 Falcon & more
  BMOVE phy%,log%,32000  ! clear new screens
  sup%=GEMDOS(32,L:0) ! supervisor mode on
  a|=BYTE{&HFF820D}
  BYTE{&HFF820D}=15
  b|=BYTE{&HFF820D}
  BYTE{&HFF820D}=a|
  IF a|<>b|  ! If Ste or Falcon (not STf not TT)
    ~XBIOS(64,L:1) ! blitter on
  ENDIF
  oldpal$=SPACE$(32)
  BMOVE &HFFFF8240,V:oldpal$,32
  stzpal$=SPACE$(32)
  ~GRAF_MOUSE(256,0) ! =OUT 4,18 hide mouse (hidem don't work with patched libs)
  key|=BYTE{&H484}         ! save keyboard
  inter|=BYTE{&HFFFA09}    ! save interrupts
  SPOKE &H484,(PEEK(&H484) AND &HFE) ! keyboad 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
  ~GRAF_MOUSE(257,0) ! =OUT 4,8 show mouse (showm don't work with patched libs)
  ~MFREE(screen1%) ! free screen buffers
  ~MFREE(screen2%)
  ~XBIOS(5,L:oldphy%,L:oldlog%,oldrez&) ! back to old screens & reso
  ~XBIOS(6,L:V:oldpal$) ! restore pal
  BYTE{&H484}=key|    ! restore keyboard
  BYTE{&HFFFA09}=inter|  !  restore interrupts
  {&H4D2}=0  ! music off
  WAVE 0,0   ! sound off
  ~GEMDOS(32,L:sup%) ! user mode on
  RESERVE ! if reserve xxx was made in hello / otherwise, $m, no RESERVE needed here
  EDIT
RETURN
' optionnals
> PROCEDURE tdbug
  ' change alternatively background colour and wait space
  ' may help you to locate bugs
  nokey
  IF tdebug!
    SETCOLOR 0,&H421
    tdebug!=NOT tdebug!
  ELSE
    SETCOLOR 0,&H124
    tdebug!=NOT tdebug!
  ENDIF
  ~INP(2)
RETURN
> PROCEDURE pmul160
  ' for BMOVES, CARD and others...
  DIM t160&(200)
  FOR y|=1 TO 199
    t160&(y|)=ADD(160,ty&(PRED(y|)))
  NEXT y|
  ' ERASE t160&()
RETURN
> PROCEDURE nokey
  ' to make sure space is no longer bashed
  WHILE PEEK(&HFFFC02)=57
  WEND
RETURN
> PROCEDURE clearpal
  ' all colours to 0
  BMOVE V:stzpal$,&HFFFF8240,32
RETURN
> PROCEDURE dboff
  ' double buffering off
  xb%=XBIOS(2)
  ~XBIOS(5,L:xb%,L:xb%,-1)
RETURN
> PROCEDURE stab
  SWAP phy%,log% ! exchange adresses to display screen you just worked on
  ~XBIOS(5,L:phy%,L:log%,0) ! set the screens at these new adresses
  '  CARD{&HFFFF8240}=&H421 ! to check which part of the vbl is used
  VSYNC ! wait 4 whole screen to be displayed
  ' CARD{&HFFFF8240}=0
RETURN
> PROCEDURE fadeon
  ' fadeon palette at adress pal%
  ' Take care : using floatint point var !
  DIM r&(16),v&(16),b&(16),dr(16),dv(16),db(16) ! final rvb component then fp offset
  DIM ipal&(16) ! intermediate calculated pal
  FOR c&=0 TO 15 ! decode & store rvb components
    col&=CARD{pal%+c&+c&}
    r&(c&)=SHR(col&,8) AND 7
    v&(c&)=SHR(col&,4) AND 7
    b&(c&)=col& AND 7
    dr(c&)=r&(c&)/7 ! calculate offset
    dv(c&)=v&(c&)/7
    db(c&)=b&(c&)/7
  NEXT c&
  FOR ty&=0 TO 2 ! calculate colours
    FOR i&=0 TO 7
      it&=7-i&
      FOR ii&=0 TO 16
        IF ty&=0
          cr&=r&(ii&)-dr(ii&)*it&
        ELSE IF ty&=1
          cr&=r&(ii&)
          cb&=b&(ii&)-db(ii&)*it&
        ELSE IF ty&=2
          cr&=r&(ii&)
          cb&=b&(ii&)
          cv&=v&(ii&)-dv(ii&)*it&
        ENDIF
        ipal&(ii&)=OR(SHL(cr&,8),OR(SHL(cv&,4),cb&))
      NEXT ii&
      VSYNC
      VSYNC
      FOR ii&=0 TO 15  ! change colours
        CARD{&HFFFF8240+ii&+ii&}=ipal&(ii&)
      NEXT ii&
    NEXT i&
  NEXT ty&
  ERASE ipal&(),r&(),v&(),b&(),dr(),dv(),db()
RETURN
> PROCEDURE fadeoff
  pal%=&HFFFF8240
  ' fadeoff palette
  ' Take care : using floatint point var !
  DIM r&(16),v&(16),b&(16),dr(16),dv(16),db(16) ! final rvb component then fp offset
  DIM ipal&(16) ! intermediate calculated pal
  FOR c&=0 TO 15 ! decode & store rvb components
    col&=CARD{pal%+c&+c&}
    r&(c&)=SHR(col&,8) AND 7
    v&(c&)=SHR(col&,4) AND 7
    b&(c&)=col& AND 7
  NEXT c&
  FOR c&=0 TO 16
    dr(c&)=r&(c&)/7 ! calculate offset
    dv(c&)=v&(c&)/7
    db(c&)=b&(c&)/7
  NEXT c&
  FOR ty&=0 TO 2 ! calculate colours
    FOR i&=0 TO 7
      FOR ii&=0 TO 16
        IF ty&=0
          cb&=b&(ii&)
          cr&=r&(ii&)
          cv&=v&(ii&)-dv(ii&)*i&
        ELSE IF ty&=1
          cv&=v&(ii&)-dv(ii&)*7
          cr&=r&(ii&)
          cb&=b&(ii&)-db(ii&)*i&
        ELSE IF ty&=2
          cb&=b&(ii&)-db(ii&)*7
          cv&=v&(ii&)-dv(ii&)*7
          cr&=r&(ii&)-dr(ii&)*i&
        ENDIF
        ipal&(ii&)=OR(SHL(cr&,8),OR(SHL(cv&,4),cb&))
      NEXT ii&
      VSYNC
      VSYNC
      FOR ii&=0 TO 15  ! change colours
        CARD{&HFFFF8240+ii&+ii&}=ipal&(ii&)
      NEXT ii&
    NEXT i&
  NEXT ty&
  ERASE ipal&(),r&(),v&(),b&(),dr(),dv(),db()
RETURN
> PROCEDURE vdicol
  ' use gemcol|(couleur) with deffill, defftext, defmark, color, etc.
  ' to match vdi colours with linea or physical palette of video shifter &hffff8240
  RESTORE vdicolours
  DIM vdicol|(15)
  FOR i|=0 TO 15
    READ vdicol|(i&)
  NEXT i|
vdicolours:
  DATA 0,2,3,6,4,7,5,8,9,10,11,14,12,15,13,1
RETURN

Leglod :
Je viens de me rappeler d'un truc, mais il me semble qu'il y des instruction qui ne marche pas quand tu met l'executable dans un dossier Auto apres compilation, je ne sais plus ou j'avais lu cela, un bouquin ou Stmag peut etre, c'est bon a savoir si t'a un programme qui plante !
Sur le STE tu peut metre un executable en automatique sans passer par le dossier auto !
Si non pour connaitre la machine il ya les cookiejar, util pour STE ou Falcon ! Il doit y avoir une autre methode pour savoir quelle machine c'est !




Shadow272 :
STE?
renvoie -1 en GFA 3.5 si l'ordi est un STE ou un TT
renvoie 0 si l'ordi n'est pas un STE ou un TT

TT?
renvoie -1 si l'odi a un 68020 ou un 68030
renvoie 0 dans les autres cas

hylst :

Les cookie jar sont utiles pour la détection du Falcon a priori oui, je m'en tiens pour le moment au ST qui me donne du fil à retordre =D
TT? STE? maintenant que tu en parles, il est vrai que ça aurait été plus court encore.
Je reposte ma dernière version depuis, qui bug avec grafmouse (même avec librairie non patchée), ce qui ne permet pas une compilation avec les librairies patchées Sad

[Vous devez être inscrit et connecté pour voir ce lien] :

Code:

' Initialisation and utils for GFA demo and games on ATARI ST in low res
' Big thanks to Lonny Pursell for all his help on compiling
' Hylst - v1.7 - 06/2011
'
hello ! general init
~INP(2)
bye ! restore everything
'
PROCEDURE hello
  ' compiler options
  $m500000 ! 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
  '
  sup%=GEMDOS(32,L:0) ! super
  compiled!=BYTE{BASEPAGE+256}<>96  ! false=interpreted/true=compiled
  IF NOT compiled!
    RESERVE 500000 ! if run under interpreter
  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
  IF screen%<=0
    ~GEMDOS(32,L:sup%)
    IF NOT compiled!
      RESERVE
    ENDIF
    EDIT
  ENDIF
  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
  CLS  ! 0 low reso  1 medium  2 high  3 reserved 4 Falcon & more
  BMOVE phy%,log%,32000  ! clear new screens
  a|=BYTE{&HFF820D}
  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)
  BMOVE &HFFFF8240,V:oldpal&(0),32
  DIM stzpal&(16)
  ARRAYFILL stzpal&(),0
  stzpal%=V:stzpal&(0)
  '  ~GRAF_MOUSE(256,0) ! =OUT 4,18 hide mouse (hidem don't work with patched libs)
  key|=BYTE{&H484}         ! save keyboard
  inter|=BYTE{&HFFFA09}    ! save interrupts
  SPOKE &H484,(PEEK(&H484) AND &HFE) ! keyboad sound off
  BYTE{&H484}=0            ! keyboard off
  CLIP 0,0,320,200 !required for patched libs otherwise gfx are not visible
  OUT 4,18
  ON ERROR GOSUB bye ! hope this doesn't slow program
  ON BREAK GOSUB bye ! to avoid disagreements in case...
RETURN
PROCEDURE bye
  '  ~GRAF_MOUSE(257,0) ! =OUT 4,8 show mouse (showm don't work with patched libs)
  ' ~MFREE(screen%) ! free screen buffer, not necessary at the end of the program :

automatic
  ~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
  {&H4D2}=0  ! music off
  WAVE 0,0   ! sound off
  OUT 4,8
  ~GEMDOS(32,L:sup%) ! user mode on
  IF NOT compiled!
    RESERVE
  ENDIF
  EDIT
RETURN
' optionnals
> PROCEDURE tdbug
  ' change alternatively background colour and wait space
  ' may help you to locate bugs
  nokey
  IF tdebug!
    SETCOLOR 0,&H421
    tdebug!=NOT tdebug!
  ELSE
    SETCOLOR 0,&H124
    tdebug!=NOT tdebug!
  ENDIF
  ~INP(2)
RETURN
> PROCEDURE pmul160
  ' for BMOVES, CARD and others...
  DIM t160&(200)
  FOR y|=1 TO 199
    t160&(y|)=ADD(160,t160&(PRED(y|)))
  NEXT y|
  ' ERASE t160&()
RETURN
> PROCEDURE nokey
  ' to make sure space is no longer bashed
  WHILE PEEK(&HFFFC02)=57
  WEND
RETURN
> PROCEDURE clearpal
  ' all colours to 0
  BMOVE stzpal%,&HFFFF8240,32
RETURN
> PROCEDURE dboff
  ' double buffering off
  xb%=XBIOS(2)
  ~XBIOS(5,L:xb%,L:xb%,-1)
RETURN
> PROCEDURE stab
  SWAP phy%,log% ! exchange adresses to display screen you just worked on
  ~XBIOS(5,L:phy%,L:log%,0) ! set the screens at these new adresses
  '  CARD{&HFFFF8240}=&H421 ! to check which part of the vbl is used
  VSYNC ! wait 4 whole screen to be displayed
  ' CARD{&HFFFF8240}=0
RETURN
> PROCEDURE fadeon
  ' fadeon palette at adress pal%
  ' Take care : using floatint point var !
  DIM r&(16),v&(16),b&(16),dr(16),dv(16),db(16) ! final rvb component then fp offset
  DIM ipal&(16) ! intermediate calculated pal
  FOR c&=0 TO 15 ! decode & store rvb components
    col&=CARD{pal%+c&+c&}
    r&(c&)=SHR(col&,8) AND 7
    v&(c&)=SHR(col&,4) AND 7
    b&(c&)=col& AND 7
    dr(c&)=r&(c&)/7 ! calculate offset
    dv(c&)=v&(c&)/7
    db(c&)=b&(c&)/7
  NEXT c&
  FOR ty&=0 TO 2 ! calculate colours
    FOR i&=0 TO 7
      it&=7-i&
      FOR ii&=0 TO 16
        IF ty&=0
          cr&=r&(ii&)-dr(ii&)*it&
        ELSE IF ty&=1
          cr&=r&(ii&)
          cb&=b&(ii&)-db(ii&)*it&
        ELSE IF ty&=2
          cr&=r&(ii&)
          cb&=b&(ii&)
          cv&=v&(ii&)-dv(ii&)*it&
        ENDIF
        ipal&(ii&)=OR(SHL(cr&,8),OR(SHL(cv&,4),cb&))
      NEXT ii&
      VSYNC
      VSYNC
      FOR ii&=0 TO 15  ! change colours
        CARD{&HFFFF8240+ii&+ii&}=ipal&(ii&)
      NEXT ii&
    NEXT i&
  NEXT ty&
  ERASE ipal&(),r&(),v&(),b&(),dr(),dv(),db()
RETURN
> PROCEDURE fadeoff
  pal%=&HFFFF8240
  ' fadeoff palette
  ' Take care : using floatint point var !
  DIM r&(16),v&(16),b&(16),dr(16),dv(16),db(16) ! final rvb component then fp offset
  DIM ipal&(16) ! intermediate calculated pal
  FOR c&=0 TO 15 ! decode & store rvb components
    col&=CARD{pal%+c&+c&}
    r&(c&)=SHR(col&,8) AND 7
    v&(c&)=SHR(col&,4) AND 7
    b&(c&)=col& AND 7
  NEXT c&
  FOR c&=0 TO 16
    dr(c&)=r&(c&)/7 ! calculate offset
    dv(c&)=v&(c&)/7
    db(c&)=b&(c&)/7
  NEXT c&
  FOR ty&=0 TO 2 ! calculate colours
    FOR i&=0 TO 7
      FOR ii&=0 TO 16
        IF ty&=0
          cb&=b&(ii&)
          cr&=r&(ii&)
          cv&=v&(ii&)-dv(ii&)*i&
        ELSE IF ty&=1
          cv&=v&(ii&)-dv(ii&)*7
          cr&=r&(ii&)
          cb&=b&(ii&)-db(ii&)*i&
        ELSE IF ty&=2
          cb&=b&(ii&)-db(ii&)*7
          cv&=v&(ii&)-dv(ii&)*7
          cr&=r&(ii&)-dr(ii&)*i&
        ENDIF
        ipal&(ii&)=OR(SHL(cr&,8),OR(SHL(cv&,4),cb&))
      NEXT ii&
      VSYNC
      VSYNC
      FOR ii&=0 TO 15  ! change colours
        CARD{&HFFFF8240+ii&+ii&}=ipal&(ii&)
      NEXT ii&
    NEXT i&
  NEXT ty&
  ERASE ipal&(),r&(),v&(),b&(),dr(),dv(),db()
RETURN
> PROCEDURE vdicol
  ' use gemcol|(couleur) with deffill, defftext, defmark, color, etc.
  ' to match vdi colours with linea or physical palette of video shifter &hffff8240
  RESTORE vdicolours
  DIM vdicol|(15)
  FOR i|=0 TO 15
    READ vdicol|(i&)
  NEXT i|
vdicolours:
  DATA 0,2,3,6,4,7,5,8,9,10,11,14,12,15,13,1
RETURN
PROCEDURE blitter(switch!)
  status&=XBIOS(64,-1)
  IF BTST(status&,1)           ! Blitter available?
    IF switch!
      status&=BSET(status&,0)   ! Blitter on
    ELSE
      status&=BCLR(status&,0)   ! Blitter off
    ENDIF
    ~XBIOS(64,status&)         ! do it
  ENDIF
RETURN

Leglod :
screen%=MALLOC(32255) ! reserve memory for double screen buffer
C'est pas un peut juste pour un double buffer ?

Strider :
Apparemment seul l'écran logique a sa propre zone mémoire, pour l'écran physique il réutilise celui fourni par le système au démarrage du programme.
Si tu veux réserver deux nouveaux espaces en mémoire pour les écrans logique et physique, il faut remplacer ceci :
Code:

 screen%=MALLOC(32255) ! reserve memory for double screen buffer
  log%=(screen%+255) AND &HFFFFFF00 ! Stf compatible adress for video shifter
  phy%=oldphy%

Par cela :
Code:

screen%=MALLOC(64255) ! reserve memory for double screen buffer (32255 + 32000)
  log%=(screen%+255) AND &HFFFFFF00 ! Stf compatible adress for video shifter
  phy%=log%+32000

(et du coup on pourrait même virer le BMOVE phy%,log%,32000)
J'espère ne pas avoir dit d'âneries... je suis un peu rouillé Wink
Shadow272
Shadow272
Admin

Messages : 328
Date d'inscription : 28/12/2017
Age : 65
Localisation : Hainaut Belgique

http://toutatari.blog4ever.xyz/

Revenir en haut Aller en bas

Revenir en haut

- Sujets similaires

 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum