Author Topic: Trying to Understand NEW FRAME FLYBACK (&BCD7)  (Read 1914 times)

0 Members and 1 Guest are viewing this topic.

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
    • Awards
I forgot about this article in AA80 Mastering Machine Code, which talks about the NEW FRAME FLYBACK (&BCD7), which was the Firmware I had to disable from the "Sprites Alive" Library in order to get "The Eternal Light" game to work on a real Amstrad.


"Sprites Alive" uses this to point to a routine which Disables Interrupts, which I think was where there was a problem accessing the extra 64k in that game, though in this example NEW FRAME FLYBACK is being used in conjunction with TXT UNDRAW CURSOR (&BDD0) to show the flickering effect of the cursor. I've had a play around with the size of Frame Block, though didn't notice any difference in result.



In the AA article I've attached, it suggests using NEW FRAME FLYBACK gives more control to your routines, rather than waiting for the FRAME FLYBACK, though I'm still confused what this means. For example if I changed the #BDD0 in that program to FRAME FLYBACK (#BD19), and execute that, the computer goes REA, followed by slowly drawing D and Y, eventually the cursor comes up, so obviously I'm not meant to point that to a FRAME FLYBACK routine. Help?  ???


[attachimg=1]

like
0
No reactions
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline Axelay

  • 6128 Plus
  • ******
  • Posts: 595
  • Country: au
    • Awards
Re: Trying to Understand NEW FRAME FLYBACK (&BCD7)
« Reply #1 on: 11:08, 02 July 16 »
The FRAME_BLOCK: is just a small data structure for adding user defined events to the event system.  Changing it's size wont change anything in that listing, unless you reduce it in size and put some code after it, which I'd expect to then be corrupted.


The reason they are saying it gives you more control is that you are creating your own 50hz event.  If you were to do the same thing using a call to FRAME FLYBACK in your code that would mean your program was halting until the 50hz event occurs, and if your program was taking longer than a 50th of a second to execute per iteration/loop or whatever it is doing, then to maintain that effect you'd need to intersperse your code with multiple calls to FRAME FLYBACK, with a lot of potential idling of the CPU.  So putting such a small routine like that in an interrupt avoids all that.  As it's already a frame flyback event, making the event itself a call to FRAME FLYBACK wont give ideal results.  :)
like
0
No reactions

Offline Docent

  • CPC6128
  • ****
  • Posts: 166
  • Country: pl
    • Awards
Re: Trying to Understand NEW FRAME FLYBACK (&BCD7)
« Reply #2 on: 23:32, 02 July 16 »
I forgot about this article in AA80 Mastering Machine Code, which talks about the NEW FRAME FLYBACK (&BCD7), which was the Firmware I had to disable from the "Sprites Alive" Library in order to get "The Eternal Light" game to work on a real Amstrad.


"Sprites Alive" uses this to point to a routine which Disables Interrupts, which I think was where there was a problem accessing the extra 64k in that game, though in this example NEW FRAME FLYBACK is being used in conjunction with TXT UNDRAW CURSOR (&BDD0) to show the flickering effect of the cursor. I've had a play around with the size of Frame Block, though didn't notice any difference in result.

In the AA article I've attached, it suggests using NEW FRAME FLYBACK gives more control to your routines, rather than waiting for the FRAME FLYBACK, though I'm still confused what this means. For example if I changed the #BDD0 in that program to FRAME FLYBACK (#BD19), and execute that, the computer goes REA, followed by slowly drawing D and Y, eventually the cursor comes up, so obviously I'm not meant to point that to a FRAME FLYBACK routine. Help?  ???


FRAME_FLYBACK just waits for the beginning of video refresh (every 50th of second for PAL and 60th of second for NTSC) while NEW_FRAME_FLYBACK adds an event handler that is called every video refresh (every 50th or 60th of second). Such event handler can be used to do stuff that requires frequent updates at the beginning of video refresh, for example position updates, color cycling etc.
in the example BDD0 is TXT UNDRAW CURSOR, which basically removes cursor from the screen. Your change to BD19 caused that the original event handler, called every 50th second waited for a frame flyback and it caused the system to slow down.
« Last Edit: 03:55, 03 July 16 by Docent »
like
0
No reactions

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
    • Awards
Re: Trying to Understand NEW FRAME FLYBACK (&BCD7)
« Reply #3 on: 06:23, 03 July 16 »

Thanks for the replies. Unfortunately that AA article has left me confused, which had me thinking that NEW FRAME FLYBACK was a more controlled method of FRAME FLYBACK. I just mean that because in the AA article they give you too BASIC examples where FRAME FLYBACK is used in one of them, and then they give you this Assembly code using NEW FRAME FLYBACK. So ironically I compiled the assembly and tested it on both BASIC programs, but saw no difference.


Because I remember NEW FRAME FLYBACK being used in Sprites Alive, I thought it might of had something to do with Reducing Flicker. So when I removed NEW FRAME FLYBACK, to run "The Eternal Light" on my real 6128, I noticed the game was running a touch faster.


So when I read your relies, I'm assuming the NEW FRAME FLYBACK is used to setup an Event when the Interrupt takes place, where's FRAME FLYBACK simply tells the computer to wait until an Interrupt has passed, hence reduce the Flicker.
like
0
No reactions
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.005
    • Awards
Re: Trying to Understand NEW FRAME FLYBACK (&BCD7)
« Reply #4 on: 14:45, 03 July 16 »
So when I read your relies, I'm assuming the NEW FRAME FLYBACK is used to setup an Event when the Interrupt takes place, where's FRAME FLYBACK simply tells the computer to wait until an Interrupt has passed, hence reduce the Flicker.
FRAME (and the equivalent firmware call) basically say "Stop doing anything and wait till a Frame Flyback event occurs". NEW FRAME FLYBACK says "Here is a piece of code which I want you to run every time a Frame Flyback occurs". The former is generally easier to understand conceptually and to use because it's a synchronous process. The latter is more efficient because the CPU never wastes time waiting, however it introduces asynchronous code and can be harder to understand because you have to get used to the idea you're never quite sure what state things are in at the time it kicks off.
like
0
No reactions

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
    • Awards
Re: Trying to Understand NEW FRAME FLYBACK (&BCD7)
« Reply #5 on: 02:49, 04 July 16 »
FRAME (and the equivalent firmware call) basically say "Stop doing anything and wait till a Frame Flyback event occurs". NEW FRAME FLYBACK says "Here is a piece of code which I want you to run every time a Frame Flyback occurs". The former is generally easier to understand conceptually and to use because it's a synchronous process. The latter is more efficient because the CPU never wastes time waiting, however it introduces asynchronous code and can be harder to understand because you have to get used to the idea you're never quite sure what state things are in at the time it kicks off.



Interesting, so what I did is use the NEW FRAME FLYBACK and point that to a simple 8bit Random Number and watch all the numbers constantly change :D


Code: [Select]

   org &9000

   ld de,program
   ld b,&81
   ld hl,frame_block
   call &bcd7
   ret

.program
   ld a,(seed)
   ld b,a
   add a,a
   add a,a
   add a,a
   add a,b
   inc a
   ld (seed),a
   ret

.frame_block
   refs 9

.seed
   defb 0



So I made a little BASIC program, which made a nice little pattern:


Code: [Select]
10 MODE 0:INK 14,11:INK 15,9
20 FOR Y%=398 TO 0 STEP -2
30   FOR X%=0 TO 640 STEP 4
40     col%=INT(PEEK(&9022)/16)
50     PLOT X%,Y%,col%
60   NEXT X%
70 NEXT Y%
80 CALL &BB18



Which makes a nice blocky patterned effect.  :)
like
0
No reactions
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
    • Awards
Re: Trying to Understand NEW FRAME FLYBACK (&BCD7)
« Reply #6 on: 13:56, 05 July 16 »
Following on in the tradition of the previous post, I've come up with some more programs using NEW FRAME FLYBACK, to produce some Silly Effects.  ;D  Unsure if it was ever intended to be used like this.


Code: [Select]

10 MODE 0:INK 0,0:INK 1,26:INK 2,16:INK 3,2:INK 4,3:INK 5,4:INK 6,1:BORDER 0
20 GOSUB 120
30 CALL &9000
40 FOR y%=398 TO 0 STEP -2
50   FOR x%=0 TO 200 STEP 4
60     col%=PEEK(&905B)
70     PLOT x%,y%,col%
80   NEXT x%
90 NEXT y%
100 CALL &9049:CALL &BB18:MODE 2:END
110 ' POKE MACHINE CODE
120 RESTORE 160 : FOR addr%=&9000 TO &9150
130 READ a$
140 POKE addr%,VAL("&"+a$)
150 NEXT addr%:RETURN
160 DATA 11,0C,90,06,81,21,50,90
170 DATA CD,D7,BC,C9,2A,5C,90,7E
180 DATA 32,5B,90,2A,5C,90,23,22
190 DATA 5C,90,3A,59,90,3C,32,59
200 DATA 90,47,3A,5A,90,B8,30,0B
210 DATA 3E,00,32,59,90,21,5E,90
220 DATA 22,5C,90,C9,DD,4E,00,DD
230 DATA 46,01,DD,5E,02,DD,56,03
240 DATA DD,6E,04,DD,66,05,ED,B0
250 DATA C9,21,50,90,CD,DD,BC,C9
260 DATA 00,00,00,00,00,00,00,00
270 DATA 00,00,F2,00,5E,90,00,04
280 DATA 04,04,04,04,04,00,00,00
290 DATA 00,00,04,04,04,04,04,04
300 DATA 04,04,04,00,00,04,04,04
310 DATA 04,04,04,02,04,04,00,04
320 DATA 04,04,04,04,04,04,02,04
330 DATA 04,00,04,04,04,04,04,04
340 DATA 02,02,02,04,04,04,04,04
350 DATA 04,01,00,02,00,01,04,04
360 DATA 04,02,04,02,01,00,02,00
370 DATA 01,04,04,00,02,04,02,01
380 DATA 00,02,00,01,04,04,00,02
390 DATA 02,02,01,00,02,00,01,04
400 DATA 00,00,04,02,02,01,01,02
410 DATA 01,02,02,00,00,04,02,02
420 DATA 02,01,02,01,02,02,00,00
430 DATA 00,04,02,02,02,02,02,02
440 DATA 02,02,00,00,03,04,02,02
450 DATA 02,00,02,02,02,00,03,03
460 DATA 03,02,02,02,02,02,02,05
470 DATA 00,03,03,03,05,03,03,03
480 DATA 05,03,05,00,03,03,02,05
490 DATA 03,03,03,05,02,02,00,03
500 DATA 02,02,02,05,05,05,05,02
510 DATA 02,00,00,02,02,05,06,01
520 DATA 06,01,05,02,00,00,05,05
530 DATA 05,05,06,06,06,06,05,00
540 DATA 00,05,05,05,05,05,05,05
550 DATA 05,05,05,00,04,06,06,06
560 DATA 00,06,06,06,06,04,00,04
570 DATA 04,04,04,00,04,04,04,04
580 DATA 04,00


Playing around with the 200 line 50 in the program above gives a whole variety of results, I liked the result 200 gave, which looks like this:


Bub on NEW FRAME FLYBACK 2.png
* Bub on NEW FRAME FLYBACK 2.png
(Filesize: 6.88 KB, Dimensions: 768x540, Views: 120)





other values around 200 (e.g. 196 & 204), give similar results, 204 puts Bub on a different slant.


The second program I made, which was actually my 1st program  ;D , draws a tiny bit of Bub across the screen, I then use the Array along with a LDIR routine to drag that tiny bit to the bottom cursor line, I don't think I've seen Bub look really creepy!  ;D


Code: [Select]

10 MODE 0:INK 0,0:INK 1,26:INK 2,16:INK 3,2:INK 4,3:INK 5,4:INK 6,1:BORDER 0
20 DIM scr%(24)
30 GOSUB 210 : GOSUB 320
40 CALL &9000
50 FOR y%=398 TO 0 STEP -16
60   FOR x%=0 TO 638 STEP 4
70     col%=PEEK(&905B)
80     PLOT x%,y%,col%
90   NEXT x%
100 NEXT y%
110 num%=0
120 WHILE num%<>25
130 FOR s%=scr%(num%) TO scr%(num%)+&4000 STEP &800
140  CALL &9034,scr%(num%),s%,&50
150 NEXT s%
160 num%=num%+1
170 WEND
180 CALL &9049 : CALL &BB18
190 MODE 2 : END
200 ' Map Screen to Array
210 RESTORE 270
220 FOR num%=0 TO 24
230   READ adr$
240   scr%(num%)=VAL("&"+adr$)
250 NEXT num%
260 RETURN
270 DATA c000,c050,c0a0,c0f0,c140,c190,c1e0
280 DATA c230,c280,c2d0,c320,c370,c3c0,c410
290 DATA c460,c4b0,c500,c550,c5a0,c5f0,c640
300 DATA c690,c6e0,c730,c780
310 ' POKE MACHINE CODE
320 RESTORE 360 : FOR addr%=&9000 TO &9150
330 READ a$
340 POKE addr%,VAL("&"+a$)
350 NEXT addr%:RETURN
360 DATA 11,0C,90,06,81,21,50,90
370 DATA CD,D7,BC,C9,2A,5C,90,7E
380 DATA 32,5B,90,2A,5C,90,23,22
390 DATA 5C,90,3A,59,90,3C,32,59
400 DATA 90,47,3A,5A,90,B8,30,0B
410 DATA 3E,00,32,59,90,21,5E,90
420 DATA 22,5C,90,C9,DD,4E,00,DD
430 DATA 46,01,DD,5E,02,DD,56,03
440 DATA DD,6E,04,DD,66,05,ED,B0
450 DATA C9,21,50,90,CD,DD,BC,C9
460 DATA 00,00,00,00,00,00,00,00
470 DATA 00,00,F2,00,5E,90,00,04
480 DATA 04,04,04,04,04,00,00,00
490 DATA 00,00,04,04,04,04,04,04
500 DATA 04,04,04,00,00,04,04,04
510 DATA 04,04,04,02,04,04,00,04
520 DATA 04,04,04,04,04,04,02,04
530 DATA 04,00,04,04,04,04,04,04
540 DATA 02,02,02,04,04,04,04,04
550 DATA 04,01,00,02,00,01,04,04
560 DATA 04,02,04,02,01,00,02,00
570 DATA 01,04,04,00,02,04,02,01
580 DATA 00,02,00,01,04,04,00,02
590 DATA 02,02,01,00,02,00,01,04
600 DATA 00,00,04,02,02,01,01,02
610 DATA 01,02,02,00,00,04,02,02
620 DATA 02,01,02,01,02,02,00,00
630 DATA 00,04,02,02,02,02,02,02
640 DATA 02,02,00,00,03,04,02,02
650 DATA 02,00,02,02,02,00,03,03
660 DATA 03,02,02,02,02,02,02,05
670 DATA 00,03,03,03,05,03,03,03
680 DATA 05,03,05,00,03,03,02,05
690 DATA 03,03,03,05,02,02,00,03
700 DATA 02,02,02,05,05,05,05,02
710 DATA 02,00,00,02,02,05,06,01
720 DATA 06,01,05,02,00,00,05,05
730 DATA 05,05,06,06,06,06,05,00
740 DATA 00,05,05,05,05,05,05,05
750 DATA 05,05,05,00,04,06,06,06
760 DATA 00,06,06,06,06,04,00,04
770 DATA 04,04,04,00,04,04,04,04
780 DATA 04,00


as the screenshot demonstrates:


* Effects using new frame flyback.zip
(Filesize: 3.47 KB, Downloads: 57)



Here's the Assembly if anyone was interested:


Code: [Select]

org &9000


ld de,program
ld b,&81
ld hl,frame_block
call &bcd7 ;; New Frame Fly
ret


.program
ld hl,(addrcolor)
ld a,(hl)
ld (byte),a


ld hl,(addrcolor)
inc hl
ld (addrcolor),hl


ld a,(fcount) ;; First Counter Position into A
inc a ;; Increment this
ld (fcount),a ;; Put New Value into First Count Position
ld b,a ;; Put this value into B


ld a,(limit) ;; Place First Counter Marker into A


cp b ;; Has value of B reached A value
jr nc,over ;; If No Loop back, otherwise continue
ld a,0
ld (fcount),a
ld hl,data_color
ld (addrcolor),hl
.over ret


.move
ld c,(ix+00)
ld b,(ix+01)
ld e,(ix+02)
ld d,(ix+03)
ld l,(ix+04)
ld h,(ix+05)
ldir
ret


.del_frame
ld hl,frame_block
call &bcdd
ret


.frame_block
defs 9
.fcount defb 0
.limit defb 242
.byte defb 0
.addrcolor
defw data_color
.data_color
defb 0,4,4,4,4,4,4,0,0,0,0
defb 0,4,4,4,4,4,4,4,4,4,0
defb 0,4,4,4,4,4,4,2,4,4,0
defb 4,4,4,4,4,4,4,2,4,4,0
defb 4,4,4,4,4,4,2,2,2,4,4
defb 4,4,4,4,1,0,2,0,1,4,4
defb 4,2,4,2,1,0,2,0,1,4,4
defb 0,2,4,2,1,0,2,0,1,4,4
defb 0,2,2,2,1,0,2,0,1,4,0
defb 0,4,2,2,1,1,2,1,2,2,0
defb 0,4,2,2,2,1,2,1,2,2,0
defb 0,4,2,2,2,2,2,2,2,2,0
defb 0,3,4,2,2,2,0,2,2,2,0
defb 3,3,3,2,2,2,2,2,2,5,0
defb 3,3,3,5,3,3,3,5,3,5,0
defb 3,3,2,5,3,3,3,5,2,2,0
defb 3,2,2,2,5,5,5,5,2,2,0
defb 0,2,2,5,6,1,6,1,5,2,0
defb 0,5,5,5,5,6,6,6,6,5,0
defb 0,5,5,5,5,5,5,5,5,5,5
defb 0,4,6,6,6,0,6,6,6,6,4
defb 0,4,4,4,4,0,4,4,4,4,4


defb 0


I've also attached a disk image, which has both of those programs on it.



like
0
No reactions
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3