Let's get it over with: paging @Crutch since I know he has tips inside his mind at the ready, with no need to consult any reference, like always.
Goal: I want to prepare an alternate screen buffer graphic a few seconds in advance so I can instantly 'screen flip' at a precise time when needed.
Motivation: under a modern day emulator, DrawPicture is so fast that it gives the impression it's instantenous - when you need it done, you call it and get it. When you bring the same program on a real Mac Plus, you obviously see a split second lag, causing problem with an application where I need to keep precise timing for a few minutes while needing to occasionally change the graphics on screen.
In the first volumes of Inside Macintosh, we get this tidbit of info:
Various ScrnBase (screen 'base' adress of the first byte of memory of the top left screen bitmap, and its alternate screen buffer, which seems 0x8000 lower than the base. Example: for a 4 MB equipped Mac Plus, its ScrnBase is at $3FA700 and its alternate address is at $3F2700).
ScrnBase is a global symbol recognized by THINK C and acts as expected. I've successfully pointed a char * to it, and started filling in the whole screen (all 21888 bytes) with a fixed byte, effectively doing the same thing as filling in a pattern-like graphic everywhere.
What do I need to do to is effectively flip flop between the 2 buffers:
1) prep the alternate screen
2) make the Mac point to it
3) prep the main screen buffer
4) make the Mac point back to main
5) goto 1)
I've actually checked out the source code of Megaroids (made under MegaMax C) from this physical copy of this book:
Programming C on the Macintosh (1986) (from Terry A. Ward)
The code does keep pointers to both buffers and seems to flip between them, but I haven't established if it's continually used on the fly, for fluid arcade like movement, or if it's to prepare a main game menu screen in advance. There's still something I don't understand about the whole technique. Here is where I have problems to come to grip with it:
Problem: If it's already too long to prepare a frame of game animation within a 1/60th of a second before the screen has to be redrawn, why would an alternate screen buffer be any useful? Say it takes 1.2 ticks (1.2 * 1/ 60 in seconds) to prep a whole screen, it's gonna take the same time to prep the alternate buffer and you just have to accept to draw at every 2 frames (every 2 ticks, or every 2 / 60 = 1 / 30 s). Just prep an offscreen bitmap for a duration that's under 2 frames and copy it onto the main screen before you hit the 2nd screen retrace and voilà! No need to mess with ScrnBase and Alternate Screen.
In my case, I never need to do things so fast, but I thought it'd be an interesting question for later purposes. There's easily 3+ s between screen changes, so 'screen flipping' might make sense in my use case.
Question: The book mentions a VIA address at 0xEFFFFE that controls which buffer is being used. How do you use it? Do I have to invalidate the screen to use it? Think C doesn't seem to have a global variable associated with it, I think? It's ok if the code only runs under a specific subclass of compact Macs. I don't care! That technique wasn't used much beyond 1984-1986 iirc. How do the pixels ACTUALLY change? Just part of the vertical retrace, automagically? No need to InvalidateRect or something like that?
Goal: I want to prepare an alternate screen buffer graphic a few seconds in advance so I can instantly 'screen flip' at a precise time when needed.
Motivation: under a modern day emulator, DrawPicture is so fast that it gives the impression it's instantenous - when you need it done, you call it and get it. When you bring the same program on a real Mac Plus, you obviously see a split second lag, causing problem with an application where I need to keep precise timing for a few minutes while needing to occasionally change the graphics on screen.
In the first volumes of Inside Macintosh, we get this tidbit of info:
Various ScrnBase (screen 'base' adress of the first byte of memory of the top left screen bitmap, and its alternate screen buffer, which seems 0x8000 lower than the base. Example: for a 4 MB equipped Mac Plus, its ScrnBase is at $3FA700 and its alternate address is at $3F2700).
ScrnBase is a global symbol recognized by THINK C and acts as expected. I've successfully pointed a char * to it, and started filling in the whole screen (all 21888 bytes) with a fixed byte, effectively doing the same thing as filling in a pattern-like graphic everywhere.
What do I need to do to is effectively flip flop between the 2 buffers:
1) prep the alternate screen
2) make the Mac point to it
3) prep the main screen buffer
4) make the Mac point back to main
5) goto 1)
I've actually checked out the source code of Megaroids (made under MegaMax C) from this physical copy of this book:
Programming C on the Macintosh (1986) (from Terry A. Ward)
The code does keep pointers to both buffers and seems to flip between them, but I haven't established if it's continually used on the fly, for fluid arcade like movement, or if it's to prepare a main game menu screen in advance. There's still something I don't understand about the whole technique. Here is where I have problems to come to grip with it:
Problem: If it's already too long to prepare a frame of game animation within a 1/60th of a second before the screen has to be redrawn, why would an alternate screen buffer be any useful? Say it takes 1.2 ticks (1.2 * 1/ 60 in seconds) to prep a whole screen, it's gonna take the same time to prep the alternate buffer and you just have to accept to draw at every 2 frames (every 2 ticks, or every 2 / 60 = 1 / 30 s). Just prep an offscreen bitmap for a duration that's under 2 frames and copy it onto the main screen before you hit the 2nd screen retrace and voilà! No need to mess with ScrnBase and Alternate Screen.
In my case, I never need to do things so fast, but I thought it'd be an interesting question for later purposes. There's easily 3+ s between screen changes, so 'screen flipping' might make sense in my use case.
Question: The book mentions a VIA address at 0xEFFFFE that controls which buffer is being used. How do you use it? Do I have to invalidate the screen to use it? Think C doesn't seem to have a global variable associated with it, I think? It's ok if the code only runs under a specific subclass of compact Macs. I don't care! That technique wasn't used much beyond 1984-1986 iirc. How do the pixels ACTUALLY change? Just part of the vertical retrace, automagically? No need to InvalidateRect or something like that?
Last edited: