4

Is there a way to detect HBL and or VBL on an Apple II, and if yes, how it's done?

5

Hardware management on the Apple II is done by accessing a set of 'Softswitches', addresses when accessed set certain modes. For the screen there are several locations:

$C050 Select Graphics 
$C051 Select Text
$C052 Full Screen (Graphics)
$C053 Mixed Screen
$C054 Page 1
$C055 Page 2
$C056 Select Low Res
$C057 Select Highres

Usually they are accessed with a read (LD*)to 'switch' the desired function on, with the value read considered as random. Except, it isn't. When reading any of these locations, the returned value is what has been read from screen RAM during video access, right before the read cycle (*1). The value is not delivered by purpose, but due being still 'present' on data lines.

The mechanic now needs a known value (but better sequence values) to be detected to synchronise. This can be on screen, as well as during the off screen (HBL) portion. The later allows the detection to run 'invisible'. Once found, cycle counting like on an Atari VCS can start to keep track of the beam.

There is a real good explanation By Bob Bishop in Softtalk of October 1982. Here's a simple HTML version.

Don Lancaster's (*2,*3) 1985 Book Enhancing Your Apple II and IIe Volume 2 calls the mechanic 'Vapor Lock', describing usage in great detail (p.193ff).

Tommy points in a comment to a nice demo game using these effects: Rasterbars in Space. The same author also did a real nifty demo spliting between low and highres not only horizontal but vertical as well: Megademo.


*1 - That means if accessed via a 4 cycle operation like LDA $C051, it will be the value the video logic accessed between the third and fourth cycle.

*2 - As fadden reminded here.

*3 - Yes, that Don Lancaster whose 1976 'TV Typewriter Cookbook' and 1978 'Cheap Video Cookbook' eventually influenced many early developers, all the way from Wozniak to Sinclair. His website 'Guru's Lair' contains not only PDFs of many of his books, but as well still new updates worth reading.

| improve this answer | |
  • 3
    I think Don Lancaster coined the term "vapor lock" for this technique (deater.net/weave/vmwprod/megademo/vapor_lock.html). Not sure if he or Bob Bishop wrote about it first. – fadden Mar 5 at 15:46
  • 2
    Bob Bishop did demo and write about it. The effect is due to the capacitance on the data bus wires holding the previous voltages. – hotpaw2 Mar 5 at 17:15
  • 1
    An important difference between the Atari 2600 and the Apple is that the Atari 2600 includes a Ram/Io/Timer (RIOT) chip which can count cycles while the CPU is doing something else. Code for the 2600 will need to poll the RIOT to find out when a timing interval is done, but one can run a bunch of arbitrary code that takes any amount of time less than the programmed interval and then wait for the RIOT to expire without having to count exactly how many cycles everything takes. – supercat Mar 5 at 22:49
  • @supercat There are many ways to work on either machine. Still, the VCS doesn't work without cycle counting. Each and every timer based wait routine will also need to sync after waiting and cycle count from there on. Bee there, done that. – Raffzahn Mar 5 at 23:00
  • 1
    @cjs: The RIOT chip included a cycle counter; the TIA would stall the CPU until the next scan line in response to a write to WSYNC. Both were used together to achieve precise long delays. – supercat Mar 9 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.