Updated GFA-BASIC Library released

Re: Updated GFA-BASIC Library released

Messagede lp060 » Sam 20 Nov 2010 23:12

Ok, I have the $w command working as I want in the compiler. :D

I'm trying to come up with a better solution to get the address of a procedure in GFA. The searching method works but its messy.
Stay tuned. ;)
Avatar de l’utilisateur
lp060
 
Messages: 144
Inscription: Dim 14 Déc 2008 23:12
Localisation: My desk

Re: Updated GFA-BASIC Library released

Messagede tomchi » Sam 20 Nov 2010 23:16

\o/

Awesome news !!!

thx :D
Avatar de l’utilisateur
tomchi
Administrateur du site
 
Messages: 342
Inscription: Mer 15 Oct 2008 20:51

Re: Updated GFA-BASIC Library released

Messagede lp060 » Dim 21 Nov 2010 01:57

Here is what I came up with:
Code: Tout sélectionner
$F< !do not check for missing returns in functions (required)
'
' If you need the addresses of several routines, just copy function get_int_adr
' put it above the routine you want the address of, and rename it to something else.
' Then call it.  Its that easy and no searching.
'
addr%=@get_int_adr
PRINT "$";HEX$(WORD{addr%},4) !dump the first word of the interrupt as a test
' if you see $48E7, it worked!
EDIT
'
FUNCTION get_int_adr !this routine must be right above the one you want the address of
  $F% !return an integer and not a float (required)
  ~BASEPAGE   !basepage -> d0 (we need a temporary place to store the address)
  $w 2040     !move.l d0,a0      ;we know a call to BASEPAGE uses d0
  $w 43FA0012 !lea    ref(pc),a1 ;this fetches the address of the routine below it
  $w 21490080 !move.l a1,128(a0) ;stuff the address into our temporary location
  RETURN LONG{BASEPAGE+128}      !fetch the address from our temporary location
ENDFUNC
PROCEDURE interrupt
  ' ref:
  $w 48E78080 !movem.l d0/a0,-(a7)
  '            interrupt code here
  $w 4CDF0101 !movem.l (a7)+,d0/a0
  $w 4E73     !rte
RETURN        !this rts is never reached (becomes dead code)


Here is what it looks like dis-assembled:
Code: Tout sélectionner
STARTADR:       jsr     INIT.l
UserCode:       jsr     _GET_INT.l
                move.l  d0,-32768(a5)
                moveq   #36,d0
                bsr     P0RCHR
                movea.l -32768(a5),a0
                move.w  (a0),d0
                ext.l   d0
                move.l  d0,d1
                moveq   #4,d0
                bsr     HEXISTR
                bsr     PXSTR
                bsr     END
_GET_INT:       bsr     BASEPAGE
                movea.l d0,a0
                lea     _INTERRU(pc),a1
                move.l  a1,128(a0)
                bsr     BASEPAGE
                movea.l d0,a0
                move.l  128(a0),d0
                rts

_INTERRU:       movem.l d0/a0,-(a7)
                movem.l (a7)+,d0/a0
                rte

                rts


As you can see the idea takes advantage of the new $w command. :D
Make sure you have the most current compiler/lib from my website, then replace the compiler with the one attached to this post.
There's also some more rules. You can pretty much do anything you want in between GFA commands with $w, but do not change registers a3 to a6. Technically you can use a3 to a6, but I would avoid it if at all possible, they must be restored before it encounters another GFA command or GFA might totally freak out. ;)

You can cut/paste the example GFA code and give it a try, then perhaps adapt it to your project. If it works as expected I'll bump the compiler version and make some proper docs and a new release. As always keep backups of your project, in case something don't work.
Vous n’avez pas les permissions nécessaires pour voir les fichiers joints à ce message.
Avatar de l’utilisateur
lp060
 
Messages: 144
Inscription: Dim 14 Déc 2008 23:12
Localisation: My desk

Re: Updated GFA-BASIC Library released

Messagede tomchi » Dim 21 Nov 2010 09:38

err ... Lonny ?

I've never managed to make your releases work :oops:

Tried Rajah's MENU.PRG today, when running compiler, it says that compiler can't find the gfa file ... whatever gfa file i choose.

Maybe shouldn't have done this, but the old compiler works , but new linker displays errors with this old compiler ...

I must have missed something but can't figure what .

Using steem, TOS 1.62

I know your releases are for mutlitasking , is that why i can't make it work ?
Avatar de l’utilisateur
tomchi
Administrateur du site
 
Messages: 342
Inscription: Mer 15 Oct 2008 20:51

Re: Updated GFA-BASIC Library released

Messagede lp060 » Dim 21 Nov 2010 10:31

GBE, the editor is for tasking. The compiler, linker, library should run anywhere. Only changes is bugs and new features. Many shell programs, like the one from Rajah often only pass the base name and not the extender, because it assumes the compiler will add it. The old compiler relied on some quirk of the TOS file system, if you tried to add and extender, but it was already there, it just ignored it. However, I removed this from my compiler update because it causes weird problems under MiNT, and the compiler ends up saying it can't find file 'test.gfa.gfa'. MiNT does not ignore the request for the duplicate extender and so the extender ends up on there twice. :shock:

I have made so many changes that the compiler, linker and libs can no longer be mixed up with older ones. Mixing them up will cause strange problems.

EDIT: Ok, I found his site and the menu program and the source file for it. It fails because he passes the name without the extender.
His menu program needs changed to work with my compiler.

If you load his source file:
Code: Tout sélectionner
' Line #803
shl_write(1+8*256,0,100,info_chemin$(3),CHR$(len_tail|)+gfa_name$+co$+c0$) !old
shl_write(1+8*256,0,100,info_chemin$(3),CHR$(len_tail|)+gfa_name$+".gfa"+co$+c0$) !new
' Line #811
e%=EXEC(0,info_chemin$(3),CHR$(len_tail|)+gfa_name$+co$+c0$,env$) !old
e%=EXEC(0,info_chemin$(3),CHR$(len_tail|)+gfa_name$+".gfa"+co$+c0$,env$) !new

If you make these 2 changes it should work. Seems to work in Hatari now. Replace the binary with the one below. ;)
Vous n’avez pas les permissions nécessaires pour voir les fichiers joints à ce message.
Dernière édition par lp060 le Dim 21 Nov 2010 20:18, édité 1 fois.
Avatar de l’utilisateur
lp060
 
Messages: 144
Inscription: Dim 14 Déc 2008 23:12
Localisation: My desk

Re: Updated GFA-BASIC Library released

Messagede lafleche » Dim 21 Nov 2010 19:31

Really cool !
Avatar de l’utilisateur
lafleche
 
Messages: 136
Inscription: Lun 25 Jan 2010 14:41
Localisation: Lille

Re: Updated GFA-BASIC Library released

Messagede tomchi » Lun 22 Nov 2010 09:28

Gorgeous I'd say :D

Ran a bit out of time since yesterday, but now, 10 minutes before i have to go to work, i can say it seems to work perfectly, except my own code :P

Will try to write a proper example this evening to post here .

Lonny, you just rule !!!!!!
Vous n’avez pas les permissions nécessaires pour voir les fichiers joints à ce message.
Avatar de l’utilisateur
tomchi
Administrateur du site
 
Messages: 342
Inscription: Mer 15 Oct 2008 20:51

Re: Updated GFA-BASIC Library released

Messagede lp060 » Lun 22 Nov 2010 09:41

Very nice! 8-) I have been tinkering with the $w command and I came up with an improved routine to fetch the address of routines. It uses a local variable instead of messing around in the BASEPAGE. I can post that if you are interested. Looking forward to seeing some example.

Well, have a fine day at work!
Avatar de l’utilisateur
lp060
 
Messages: 144
Inscription: Dim 14 Déc 2008 23:12
Localisation: My desk

Re: Updated GFA-BASIC Library released

Messagede tomchi » Mer 24 Nov 2010 00:14

Yeah, using a local variable would be fine :)

Well, I really wanted to put some nice example, but in two days, i only have this .

Using the compiler commands works perfect.
As for not having the prog to crash is another deal :P
The example shows 8 rasterbars moving with a sinewave, thing is that if one plays a bit with this code, then the prog crash if you change rasterbars number to 5 for example.
Reason is if your main code doesn't take much cpu time, then you have to code a repeat/until loop to wait , using only VSYNC will make the prog freeze.

This example can be done in 100% GfA without any trick, but source code would be much longer, and it may be much harder to code because of timings needed to change colours.
Moreover, with this new technique, one can make rasters on only a few scalines wherever in the screen, which is not that possible with old technique.

Anyway here it is.
Code: Tout sélectionner
'
$F< !do not check for missing returns in functions (required)
'
RESERVE 60000
'
buffer%=MALLOC(3040)                            ! main buffer
raster%=buffer%                                 ! colour 15 rasters buffer
raster_buffer%=ADD(raster%,800)                 ! bars buffer 1
raster_buffer2%=ADD(raster_buffer%,400)         ! bars buffer 2
sincb%=ADD(raster_buffer2%,400)                 ! sine wave buffer
pal%=MALLOC(32)
'
super%=GEMDOS(&H20,L:0)                         !supervisor mode
'
rez&=XBIOS(4)                                   ! backup resolution
IF rez&                                         ! not low rez ?
  ~XBIOS(5,L:-1,L:-1,0)                         ! low rez !
ENDIF
.
@calc_me_some_colours
@calc_me_a_sine_wave
.
CLS
OUT 4,18                                        ! no more
HIDEM                                           ! mouse
CLS
.
BMOVE &HFFFF8240,pal%,32                        ! backup current palette
FOR i&=0 TO 15                                  ! paint
  SETCOLOR i&,0                                 ! in
NEXT i&                                         ! black
@print_me_something
.
' locate address of procedure to be in interrupt
vga%=@get_int_adr
.
vector120%=LONG{&H120}                        ! backup vector $120
inter|=BYTE{&HFFFA09}                         ! backup interrupts
BYTE{&HFFFA09}=0                              ! cut interrupts
BYTE{&HFFFA1B}=0                              ! disable timer b
BYTE{&HFFFA17}=BSET(BYTE{&HFFFA17},3)         ! SOFTWARE END OF INTERRUPT
'
LONG{&H120}=vga%                              ! put procedure in timer b vector
'
BYTE{&HFFFA07}=BYTE{&HFFFA07} OR 1            ! turn on timer b in enable a
BYTE{&HFFFA13}=BYTE{&HFFFA13} OR 1            ! turn on timer b in mask a
BYTE{&HFFFA21}=1                              ! number of counts
'
REPEAT
  VSYNC
  BYTE{&HFFFA1B}=0                            ! stop timer b
  SWAP raster_buffer%,raster_buffer2%
  rst%=raster_buffer%                         ! pointer in the displayed pattern
  rst2%=raster_buffer2%                       ! pointer in the work pattern
  rst2_max%=ADD(raster_buffer2%,400)          ! pointer to the end of pattern
  ADD rst15&,2                                ! scroll in col 15 raster pattern
  IF rst15&=386                               ! loop
    rst15&=0
  ENDIF
  rst15%=ADD(raster%,rst15&)                  ! pointer in col 15 raster pattern
  .
  REPEAT                                      ! waits for 1st
    b|=BYTE{&HFFFF8209}                       ! scanline
  UNTIL b|                                    ! to be
  ~SHL(13,-b|)                                ! reached
  .
  BYTE{&HFFFA1B}=8                            ! set to event count mode=launch
  .
  coul0&=0
  REPEAT                                      ! clear
    CARD{rst2%}=0                             ! work
    ADD rst2%,2                               ! raster
  UNTIL rst2%=rst2_max%                       ! pattern
  ADD pos_in_cb&,2                            ! move inside sine wave pattern
  IF pos_in_cb&=720                           ! loop
    pos_in_cb&=0
  ENDIF
  FOR nb_of_bars&=0 TO 7                      ! 8 sine rasterbars
    .calc pos of each rasterbar
    bar%=ADD(raster_buffer2%,CARD{ADD(sincb%,ADD(pos_in_cb&,MUL(nb_of_bars&,20)))})
    .
    FOR i&=1 TO 13                            ! each bar is 13 lines
      CARD{bar%}=bar&(i&)                     ! write colour value in buffer
      ADD bar%,2
    NEXT i&
  NEXT nb_of_bars&
  .
UNTIL PEEK(&HFFFFFC02)=57
@fin
> FUNCTION get_int_adr !must be right above the one you want the address of
$F%         !return an integer and not a float (required)
~BASEPAGE   !basepage -> d0 (we need a temporary place to store the address)
$w 2040     !move.l d0,a0      ;we know a call to BASEPAGE uses d0
$w 43FA0012 !lea    ref(pc),a1 ;this fetches the address of the routine below it
$w 21490080 !move.l a1,128(a0) ;stuff the address into our temporary location
RETURN LONG{BASEPAGE+128}      !fetch the address from our temporary location
ENDFUNC
> PROCEDURE timer_b
' ref:
$w 48E78080 !movem.l d0/a0,-(sp)       ! save registers
' interrupt code
CARD{&HFFFF8240}=CARD{rst%}            ! rasterbar
CARD{&HFFFF825E}=CARD{rst15%}          ! colour 15 rasters
ADD rst%,2                             ! points to next
ADD rst15%,2                           ! points to next
'
BYTE{&HFFFFFA0F}=BCLR(BYTE{&HFFFFFA0F},0) ! interupt is done
'
$w 4CDF0101 !movem.l (sp)+,d0/a0       ! restore registers
$w 4E73     !rte                       ! return from exception
RETURN
.
> PROCEDURE calc_me_some_colours
DIM bar&(13)
FOR i&=1 TO 7
  bar&(i&)=i&
NEXT i&
FOR i&=8 TO 13
  bar&(i&)=SUB(14,i&)
NEXT i&
r&=7
v&=0
b&=0
FOR i&=0 TO 7
  b&=i&
  coul&=SHL(r&,8) OR SHL(v&,4) OR b&
  CARD{raster%+i&*2}=coul&
NEXT i&
a&=0
FOR i&=7 DOWNTO 0
  r&=i&
  coul&=SHL(r&,8) OR SHL(v&,4) OR b&
  CARD{raster%+a&*2+16}=coul&
  INC a&
NEXT i&
FOR i&=0 TO 7
  v&=i&
  coul&=SHL(r&,8) OR SHL(v&,4) OR b&
  CARD{raster%+i&*2+32}=coul&
NEXT i&
a&=0
FOR i&=7 DOWNTO 0
  b&=i&
  coul&=SHL(r&,8) OR SHL(v&,4) OR b&
  CARD{raster%+a&*2+48}=coul&
  INC a&
NEXT i&
FOR i&=0 TO 7
  r&=i&
  coul&=SHL(r&,8) OR SHL(v&,4) OR b&
  CARD{raster%+i&*2+64}=coul&
NEXT i&
a&=0
FOR i&=7 DOWNTO 0
  v&=i&
  coul&=SHL(r&,8) OR SHL(v&,4) OR b&
  CARD{raster%+a&*2+80}=coul&
  INC a&
NEXT i&
BMOVE raster%,raster%+96,96
BMOVE raster%,raster%+192,192
BMOVE raster%,raster%+384,384
RETURN
.
> PROCEDURE calc_me_a_sine_wave
FOR i&=0 TO 359
  sincbp%=ADD(sincb%,i&*2)
  CARD{sincbp%}=(92+INT(92*SINQ(i&)))*2
  CARD{ADD(sincbp%,720)}=CARD{sincbp%}
NEXT i&
RETURN
.
> PROCEDURE print_me_something
'
PRINT "****************************************"
PRINT "*                                      *"
PRINT "*                                      *"
PRINT "*                                      *"
PRINT "*         99 % PURE GFA DEMO           *"
PRINT "*                                      *"
PRINT "*        USING LONNY PURSELL'S         *"
PRINT "*                                      *"
PRINT "*                                      *"
PRINT "*         LAST COMPILER UPDATE         *"
PRINT "*                                      *"
PRINT "*                                      *"
PRINT "*        GGGGG  FFFFF  AAAAA           *"
PRINT "*        G      F      A   A           *"
PRINT "*        G  GG  FFF    AAAAA           *"
PRINT "*        G   G  F      A   A           *"
PRINT "*        GGGGG  F      A   A           *"
PRINT "*                                      *"
PRINT "*                                      *"
PRINT "****************************************"
RETURN
.
PROCEDURE fin
BYTE{&HFFFA1B}=0              ! stop timer b
CLS
BMOVE pal%,&HFFFF8240,32      ! restore old palette
LONG{&H120}=vector120%        ! restore old timer b vector
BYTE{&HFFFA09}=inter|         ! set interrupts back
~GEMDOS(&H20,L:super%)        ! back in user mode
VSYNC
OUT 4,8                       ! mouse is
SHOWM                         ! back
~MFREE(buffer%)               ! clears buffer
EDIT
RETURN
Vous n’avez pas les permissions nécessaires pour voir les fichiers joints à ce message.
Avatar de l’utilisateur
tomchi
Administrateur du site
 
Messages: 342
Inscription: Mer 15 Oct 2008 20:51

Re: Updated GFA-BASIC Library released

Messagede lafleche » Mer 24 Nov 2010 18:44

two thumbs up :)
Avatar de l’utilisateur
lafleche
 
Messages: 136
Inscription: Lun 25 Jan 2010 14:41
Localisation: Lille

PrécédentSuivante

Retourner vers English section

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 1 invité

cron