# HANDY Release 1.2a 29-Mar-90 Confidential and Proprietary ## Update Notes This document contains the following sections: - [Update notes](#update-notes) - [Contents of Handy release 1.2a](#contents-of-handy-release-12a) - [`6502:` changes](#6502-changes) - [REDEYE!](#redeye) - [What to do to use this release](#what-to-do-to-use-this-release) - [Tips and Gotchas](#tips-and-gotchas) Release 1.2 was distributed to the programmers at Epyx, and based on their experiences installing Redeye, some changes have been made to release 1.2a so that installation should be much easier. Let me know if you have any problems, questions or comments. Have fun, Stephen H. Landrum c/o Epyx, Inc. 600 Allerton Dr. Redwood City, CA 94063 (415) 368-3200 x14 ## Contents of Handy Release 1.2a This release contains this documentation, an Amiga disk (Quarterback V2.2 format) and a new keyboard template (I sent out the wrong one last time). The Quarterback disk "Handy Release 1.2a" contains a complete replacement for the `6502:` directory, the new program `VAL` in the `C2:` directory, and the files `Release_1.1` and `Release_1.2` (documentation for last release and this release) in the top level directory. ## `6502:` Changes New files have been added to the `6502:` directory for the Redeye (ComLynx) communication routines: - `6502:include/msgmgr.i` - `6502:macros/msgmgr.mac` - `6502:src/comlink.src` - `6502:src/comlink_logon.src` - `6502:src/comlink_variables.src` - `6502:src/msgmgr.src` - `6502:src/msgmgrRam.src` The following changes were made to existing files in the `6502:` directory: - `6502:include/harddefs.i` Removed `MAGRDYx` definitions (`MAGTAPE` features are removed from new chips) Added new stereo hardware definitions - `6502:macros/display.mac` Removed the `DISPLAY_ON/OFF` macros `SETDISP...` macros no longer `SEI`, `CLI` Tightened up `WAITEOF`, `WAITNEOF` macros Moved initialization of `DISPCTL_RAM` to `INITSYS` Removed `BufferAddrL`, `BufferAddrH` variables - `6502:macros/sys.mac` `INITINT` no longer uses `SEI`, `CLI` `INITINT` no longer requires second argument (it sets the vectors to point to `IntReturn`) and now resets serial IRQs if `SERIALPORT_USER` defined Moved initialization of `DISPCTL_RAM` to `INITSYS` - `6502:src/display.src` Updated for new IRQ handler Removed `SEI`, `CLI` from `InitDisplayer`, `InitEOF`, `InitEOL` - `6502:src/hmusic.src` Updated for new IRQ handler - `6502:src/hsfx.src` Updated for new IRQ handler - `6502:src/sys.src` IRQ handler rewritten; only 1 IRQ at a time handled; if `SERIALPORT_USER` defined then quick check made for serial IRQ; IRQ routines must now exit with `PLX PLA RTI` instead of `RTS` - `6502:src/sysdata.src` Added shadow `INTSET_RAM` for IRQ handler Removed `BufferAddrL`, `BufferAddrH` variables In addition, most of the programs in the `6502:examples` directory were modified for compatibility with changes in the system routines. The following other changes were made to the `6502:examples` directory - `6502:examples/testeol.src` This file has been removed. The usefulness/reliability of the `WAITEOL`, `WAITNEOL` macros is in doubt. - `6502:examples/testhprint.src` This program has been modified to work on the Howard systems. Instead of `BRK`'ing and waiting for `GO`'s from Handebug, it now waits for button presses to change messages. - `6502:examples/testredeye.src` This program has been added as an example of use of Redeye. - `6502:examples/redeye_glue.src` An example of interface code to communicate with Redeye, included by `testredeye.src` ## REDEYE! At last, it's here! The long awaited Redeye (ComLynx) communication release. Some programs have gone out with old, cumbersome and buggy versions of communications software. Now we have the **NEW AND IMPROVED** version with higher reliability, more players supported, (now how much would you pay?) easier interface, (but wait, there's more) and SMALLER SIZE! Redeye does not come without some costs, however. Installation is not trivial, so I will try to describe what Redeye does, doesn't do and how to install and use it. There have also been some other significant changes to some of the other system routines, so make sure that you update your code for the 1.2a release and test it before attempting to install the redeye code. Please be sure to read through this section before attempting to install Redeye in your code. ### Overview Redeye communication is handled in a round-robin communication-frame based system. When all is going well, player 0 (the master) gives out his information, followed immediately by player 1, player 2, etc. The acknowledge of receipt of messages is implied by sending new data out. Even if a unit has nothing new to add to the state of the universe, he must send out a message so that everyone else knows their messages have all been received. If there is any problem, the master acts as the director prompting units for their data if they are late sending, and retransmitting data if anyone else requests something they have missed. This is all handled by the system routines during interrupts, and doesn't need to be dealt with by the game program. To keep the process going smoothly, a handshake protocol must be obeyed between the game code and the system communication software. This handshake has been isolated to a few glue routines in `redeye_glue.src` in the `6502:examples` directory. To get to a normal communication state, the system needs information about other players, so the process starts with a logon. Redeye logon uses a system very similar to many ethernet style two-wire communication systems. Each unit initially assigns itself player number zero, waits for a while, and then announces its identity to the world. If a unit hears someone else claim the same number the unit thinks it has, it picks a new player number that it hasn't heard claimed. After any communication, a unit waits a random amount of time (short if it has the next sequential number, intermediate if it has the next used number but unused ones precede it, and long if someone else is to speak next). Randomness is thrown into the time delays so that if two units think they have the same number, they won't speak at identical times. When all units agree about the state of the system, and a user has requested logon termination, the request is acknowledged and the process ends. If a user has requested termination, but units don't agree, termination will be delayed, and may be denied awaiting another termination request. After logon is complete, Redeye shuts down completely allowing the game that needs the space to overwrite the logon specific code before starting up normal communication. ### TESTREDEYE.SRC Example The `testredeye.src` program can be assemled and downloaded to see a very simple example of Redeye usage. The first screen that comes up is the logon screen. It displays a message in the center of the display ("LOGON IN PROGRESS") and two single hex digits below the message. The digit on the left shows the player number currently assigned to this unit, and the right digit shows 1 less than the total number of units logged in. Pressing A or B button on any unit should exit logon, and enter the "game". On the "game" screen, a number of colored arrowhead shapes fly out from the center in different directions. A set of two-digit hex numbers are displayed on the left edge of the screen (colored the same as the flying shapes). Every time a player pushes down on their joystick or presses a button on their unit (except `PAUSE`), their number will increment. Pressing left or right on a joystick causes that player's shape to spin around. `FLIP` and `RESET` are supported in the example program. ### Installation and Use To install Redeye, you need to include the following files in your code: ``` 6502:include/msgmgr.i 6502:macros/msgmgr.mac 6502:src/comlink.src 6502:src/comlink_logon.src 6502:src/msgmgr.src 6502:src/comlink_variables.src 6502:src/msgmgrRam.src ``` The file `comlink_logon.src` can be included within a segment that is overwritten after logon is complete. The other `.src` files must be included where they will be resident both during logon and normal communication. The files `comlink_variables.src` and `msgmgrRam.src` reserve space for variables and are best included either at the beginning or end of a segment so that space does not have to be reserved in the cartridge ROM. Also be aware that `msgmgr.src` includes some self-modifying code. The Redeye system files require that the user define the following constants and swithes before including: - `SERIALPORT_USER` This switch should be defined to let the system know that you use the serial (redeye) port. - `GAME_ID` The unique game ID number. Range: `1` to `$fffe` The following numbers are in use: ||| |---|---| |0|test programs| |1|Gauntlet the Third Encounter| |2|Zarlor Mercenary| |3|California Games| |4|Xenophobe| |5|Slime World| |`$ffff`|test programs| - `MAX_PLAYERS` The maximum number of players this game allows. Range: `2` to `16` - `PLAYER_DATA_SIZE` The maximum size of data contained in a player's message. Range: `1` to `256`/`MAX_PLAYERS` - `VAR_SIZE_DATA` This switch enables code to deal with variable sized messages. Only define if you want variable size messages. The Redeye routines also require that you provide the following variables (preferably in zero page): - `NumberOfPlayers` - number of players logged in -1 - `PlayerNumber` - player number assigned to this unit > ### Note > > At this point, if you only want to pass around joystick information in your program, you might want to skip down to the [Quick installation]() subsection. To start the logon process, call the system routine `start_logon`. The logon process will run unattended from the interrupt routines. The game should give some feedback to the user about what is going on. The following variables are used for communication to/from the logon code: - `EndLogonRequest` - request to end logon, game code sets to non-zero to request logon termination - `LogonInProgress` - status of logon, non-zero during logon reset when logon is over - `NumberOfPlayers` - 1 less than number of players logged in - `PlayerNumber` - current number assigned to this unit The game code should only write to `EndLogonRequest`. The logon process may reject a request for termination, and the request will need to be re-asserted. `PlayerNumber` may change during logon, and may even be set to a higher number than `NumberOfPlayers`. During logon termination, player numbers will be packed down, and after logon `PlayerNumber` will be no larger that `NumberOfPlayers`. Logon may terminate from any machine's request, so the game code should poll `LogonInProgress` even if `EndLogonRequest` has not been set. The routine `checklogonover` in `redeye_glue.src` shows an example of interface to the logon code, where termination is requested by players hitting the A or B buttons. The loop in the middle of the routine `showlogonscreen` in `testredeye.src` shows a simple example of a display that conveys some information about the logon process. After logon, when the game is ready to begin, call the system routine `start_comlink` to re-install the Redeye interrupts and prepare for normal communication. During normal communication, the following variables are used for communication and handshake to and from the system redeye routines: - `OutGoingData` - buffer for outgoing data - `Seq` - flag for whether on even/odd data sequence, zero means read `ODD` sequence data, non-zero means read `EVEN` sequence data - `PlayerData0` - incoming even sequence data, arranged as `MAX_PLAYERS` number of sequential arrays with `PLAYER_DATA_SIZE` number of elements in each - `PlayerData1` - incoming odd sequence data, arranged as `MAX_PLAYERS` number of sequential arrays with `PLAYER_DATA_SIZE` number of elements in each - `PlayerFlag0` - array of flags for whether players' even sequence data has come in/has been used negative means valid data to read, game code sets to positive to acknowledge data used - `PlayerFlag1` - array of flags for whether players' odd sequence data has come in/has been used negative means valid data to read, game code sets to positive to acknowledge data used The following variables are used when the `VAR_SIZE_DATA` switch is set: - `OutGoingSize` - how many bytes of data in `OutGoingData` Range: 0 to PLAYER_DATA_SIZE - `PlayerDataSize0` - array for each player of how many bytes received in `PlayerData0` - `PlayerDataSize1` - array for each player of how many bytes received in `PlayerData1` In addition, the constant array `PlrOffsets` is an array of offsets into the `PlayerData0` and `PlayerData1` arrays to the beginning of a player's data. For each frame of communication, the game code should put its outgoing data in the array `OutGoingData` and set `OutGoingSize` (if using `VAR_SIZE_DATA`). Call the routine `launch_redeye` to signal to the system code that your data is ready. The routine `preparejoysticks` in `redeye_glue.src` shows an example of preparing data to send. The first frame of communication will require setting up outgoing data before processing incoming data, so in the example program `do_start_comlink` branches to `preparejoysticks`. Incoming data is more complicated to deal with. Incoming data is accumulated in the `PlayerData0` and `PlayerData1` arrays for even and odd sequence frames. The variable `Seq` signals whether the game code should deal with the even or odd sequence frames - note that `Seq` is zero when reading an `ODD` frame, and non-zero when reading an `EVEN` frame. The game code should deal with each player's data sequentially from player zero to the highest numbered player. The bytes in the arrays `PlayerFlag0` and `PlayerFlag1` are set negative when the appropriate frame data has been received. After the game code is through with the data from a player, it should reset the `PlayerFlag0` or `PlayerFlag1` value to positive to acknowledge receipt and use of the data. After the flag is reset, the Redeye code may immediately overwrite the data, so it can only be reset after the data is completely used. The `PlayerData0` and `PlayerData1` buffers are read-only and should not be modified by the game code. The array `PlayerDataSize` contains the size of the incoming messages (if `VAR_SIZE_DATA` is set). The routine `getinput` in `redeye_glue.src` shows an example of how to read and acknowledge data. ### Quick Installation For those games that only want to pass around joystick information, the file `redeye_glue.src` in the `6502:examples` directory contains all of the interface code necessary to communicate with Redeye. The example program `testredeye.src` in `6502:examples` includes the sample glue code. The provided glue code expects `PLAYER_DATA_SIZE` to be set to 2. Defining the switch `VAR_SIZE_DATA` will slightly increase code size, but will improve system performance. The glue code also needs the following variables and arrays to be provided: ||| |---|---| |`restartflag`|1 byte| |`restartcount`|1 byte| |`joystick`|`MAX_PLAYERS` bytes| |`oldjoystick`|`MAX_PLAYERS bytes| |`switch`|`MAX_PLAYERS bytes| |`oldswitch`|`MAX_PLAYERS bytes| In addition, the glue code calls the routine showlogonscreen which is assumed to be code which will display a screen giving some feedback to the user about the state of logon, and which should also handle double-buffering of the display. The variables `NumberOfPlayers` and `PlayerNumber` are available for feedback. See the example routine `showlogonscreen` in `testredeye.src`. To start the logon process, call the routine `do_logon`. Control will be returned when logon is ended (by some player pressing the A or B button). Call the routine `do_start_comlink` sometime after logon, but before your main game loop begins. Call `do_comlink_joysticks` once per game frame to get communication about other players' inputs. `RESET` and `FLIP` are both handled by the glue code during logon and during normal communication. `RESET` assumes that the address restart will be provided as a location to jump to to restart the code. After logon, `NumberOfPlayers` is set to one less than the number of players connected and `PlayerNumber` is set to the number assigned to the local unit. During gameplay, the arrays `joystick` and `switch` reflect the current input values being used by each of the players. The arrays `oldjoystick` and `oldswitch` contain the previous game frame's values for inputs. The routine `do_start_comlink` initializes the elements of each of the arrays to `$FF`, and the routine `do_comlink_joysticks` copies the current values to the old, and gets new current values from the Redeye communication buffers. The glue code provided is just an example, but can be used directly by your code in its current state. Feel free to modify it, but make sure that you copy it out of the `6502:` directory first. ### Reset and Power-Down Timeout Game reset and Redeye bring up some interesting issues. For the sake of reliability and stability of the communication routines, it is best if units reset together. Redeye will screw up if two games in progress with two or more players are connected together, and this situation is easy to achieve if units can reset locally and then start a new game, while other units have not reset. In general if the circumstances that signal reset are noticed, then one more frame of communication should be allowed before resetting so that all units have a chance to notice the same conditions. The program `testredeye.src` checks for players pressing reset in the game loop `processplayers`, and if found, sets a bit in `restartflag`. After the next time the glue routine `getinput` is called (allowing a complete communication frame), the flag is checked to see if the game should reset. Another situation arises if one player has disconnected or lost power. Communication will go down, and if everyone has to wait for a frame of communication before reset can be handled, they cannot reset. In Testredeye the problem is solved by checking for local reset when waiting for incoming data, and if a local reset occurs, starting a timeout until deciding that communication is down and the system should be reset locally. Lynx games should turn off after a period of inactivity. This is to both save batteries and to lengthen the lifetime of the system. The switch `AUTO_TIMEOUT_USER` enables some system code in the end of frame IRQ handler that checks for activity on the joystick, and if there is none for a long enough period of time, shuts off power to the system. Redeye games, however, have the potential for situations where one player is inactive while others are continuing on (he's completed a level early, died, or is just waiting for other players to catch up) and it would be very frustrating if his unit spontaneously shut off killing everyone's game. The example program solves this with the routine `checkinactivity` , which checks for activity on any unit and uses the system macro `RESET_TIMEOUT` to reset the timeout count. Games that don't pass joystick information may need more sophisticated checks. ### Redeye Limitations The Lynx hardware can electrically support up to 18 units connected together. For a number of reasons, 16 seems like a natural software maximum for the number of players. If someone has a specific need for more than 16 players, let me know. The `PlayerData0` and `PlayerData1` arrays are assumed (for code size reasons) to each exist within a page. Therefore, `MAX_PLAYERS*PLAYER_DATA_SIZE` cannot exceed 256. If someone needs this to be different, let me know. Redeye can only add/drop players during logon. If your game needs to have places where players can add in or drop out, you will need to re-enter logon, and after logon, sort out who is who since all player numbers will be likely to be different. For a while, there was talk of a "joystick only" version of Redeye. After much thought about the problem, it seemed that the `VAR_SIZE_DATA` option provides better flexibility, since joystick values need be sent only when they are different. Redeye logon variables are overlaid in the same space as the regular communication variables, so the game program must know which state it is in when referencing variables. Receipt of the local system's messages must be handshaked in exactly the same way as all of the other players' data (even though the data is already known). Redeye provides synchronization to the game frame, but this is not enough synch for precisely timed events, such as two machines playing different voices of the same piece of music. Due to possible communication problems, the game frame when using Redeye is not guaranteed to happen at any particular rate. In practice, however, no problems have been observed. ### Resource Usage Redeye uses the serial port (timer 4) and two more general purpose timers (timers 1 and 5) during logon. After logon, redeye shuts down all three timers' interrupts. During normal communication, if only one player is playing, the timers are not used. If more than one player, then the serial port (timer 4) and one more general purpose timer (timer 1) are used. During recent assembly of the testredeye program, the Redeye system code (including variables and logon code) used the following amount of memory: ``` 2103 + MAX_PLAYERS*(4+2*PLAYER_DATA_SIZE) bytes If VAR_SIZE_DATA, add 50+(2*MAX_PLAYERS) bytes If MAX_PLAYERS>8, add 110 bytes ``` The logon code takes 745 bytes (765 if `MAX_PLAYERS>8`), which can be reclaimed after logon. In addition, the example "glue code" in `redeye_glue.src` takes approximately 380 bytes. During communication, Redeye interrupts happen very frequently. A byte takes 176 µsec to send (slightly longer than 1 scan line). Each message, Redeye sends 3 bytes of overhead (1 byte each of size, header and checksum) and any data bytes the message may contain. If there is a problem (someone missed data, or someone is late with their data), extra messages will be sent. If frequent or long lasting interrupts other than Redeye are running in the system, communication overhead can go way up. (The music and sound effects drivers have long interrupts, but both clear interrupt disable to minimize interference with Redeye). ### Optimization Shorter messages take less time to send and cause fewer interrupts. The use of `VAR_SIZE_DATA` to optimize message length can greatly improve system performance. If code space is more important than system performance, some memory can be saved by not selecting `VAR_SIZE_DATA`. Redeye code grows significantly when supporting more than 8 players. The advantages of a 9 or 10 player game may not justify the code increase. Redeye code can shrink if some of its variables are moved to zero page. The routine `ZeroComlinkVariables` in `comlink.src` would need to be modified to reflect the change. Let me know if someone needs or is making this optimization. The example program `testredeye.src` sets up `OutGoingData` only after the receipt of the message from the highest numbered player. This is fine when all of the Redeye data is dealt with at once, and not distributed through the game logic. An optimization could be made by setting up `OutGoingData` and calling `launch_redeye` immediately after acknowledging receipt of the local system's message. > ### Note > > The value of `Seq` changes on every call to `launch_redeye`, but the messages not read from higher numbered players will still belong to the same sequence. This optimization is most effective when the game frame is long, and Redeye data is processed slowly throughout the game frame. In final release code, make sure that `BRK_USER` is not defined (unless your code uses the `BRK` instruction itself). Setting `BRK_USER` enables debugging capabilities on the Mandy/Pinky systems, but adds code and time overhead to the system IRQ handler. ### Debugging Multi-system code presents special difficulties in debugging, and is prone to a peculiar class of bugs not found in single-system code. In games that only pass joystick information, it is critical that every system agrees on the state of everything important to the game. A technique found to be very useful in debugging "Gauntlet the Third Encounter" was to checksum the important variable space, and send the checksum along with the joystick data. After receiving a frame of data, the checksums were compared, and if any were different the game broke to the monitor for debugging. Important variables or state flags can also be passed around and checked this way. Counters and random number generators should be initialized to a known state immediately following logon. Care should be taken to make sure that counters and random numbers do not change based on local or system specific reasons. ## What to Do to Use This Release - Change directory to the root of your hard disk `cd DH0B:` ; (or whatever you call your hard disk) - Delete (if it exists) the directory `6502.old` `Delete 6502.old all` - Rename the directory `6502` to `6502.old` `Rename 6502 6502.old` - Create a new directory `6502` `Makedir 6502` - Assign `6502:` to `6502` `Assign 6502: 6502` Run Quarterback, and restore all of the files to your hard disk. If you keep `6502` and `C2` on separate hard disks or partitions, you will have to selectively restore them separately to appropriate disks. Edit your source files to update them. Do not install redeye in your code until you have your code tested and working with the rest of this release. The macros `DISPLAY_ON` and `DISPLAY_OFF` no longer exist, and should be removed from your code. The display is now turned on in the `INITSYS` macro, and should never be turned off (for hardware reasons). `SEI` and `CLI` pairs have been removed from many of the system initialization macros (I *HATE* macros that leave interrupts enabled without my knowledge or control). The macros `INITINT`, `INITEOF`, and the `SETDISP...` macros should only be invoked when interrupts are disabled (the `I` bit is set). Check your initialization code to make sure this is true. The system IRQ handler has been optimized to improve IRQ performance in general, and Redeye performance in particular. Routines dispatched from the interrupt handler can no longer `RTS` to exit, but must use `PLX PLA RTI`. The X and A registers no longer need to be preserved for the handler, and code which did that can now be removed. ## Tips and Gotchas The new `VAL` program supplied in the `C2` directory is a simple command-line calculator program that I use all the time. It accepts simple numeric expressions and evaluates from left to right. The answer is printed in both hex and decimal. Numbers are assumed decimal unless prefixed with a dollar sign (`$`). Operators accepted are `+`, `-`, `/`, `*`, `&` (bitwise `and`), `^` (bitwise `xor`), `<` (left shift), `>` (right shift), and expressions can be grouped with `[` and `]`. ``` > VAL 1234 1234 ($4d2) > VAL 3*[1+2] 9 ($9) > VAL 1<12 4096 ($1000) ``` There are three lights on the front of the Howard box. The left light (green) just indicates that the system is on. The middle light (yellow) is the power-on indicator for the Lynx (the Lynx can shut off its own power, but on the Howard board it only shuts off this light). The right light (red) indicates ROM access. The switch on the front indicates whether the system is running off of batteries (switch to the right) or an AC adaptor (switch to the left). The system supplied timeout power-down routines will time out quickly if running on batteries (approx. 5-6 minutes) and slowly if running an AC adaptor (approx. 1 hour). *HandyAsm* (or just `asm` as installed on most systems) has a nasty little hidden "feature" (bug). When generating multiple output files with the `.TF` directive (almost all programs will do this when they start getting broken up for cartridge loading), the first `.TF` file that contains a reference to a variable defined within the framework of another `.TF` file will generate a mangled output file. Blue Lightning's workaround was to create a `.TF` file with one external variable reference in it, just to be thrown away. The assembler is case-sensitive with respect to labels. *Handebug*, however, is not. If code generates the labels `FRED`, `Fred` and `fred`, then *Handebug* will only remember one of them when loading the symbol table. The Howard board needs to have the value `$3000` in the NMI vector to handle NMI properly, but does not initialize this value in the RAM vectors. Code in development can store the value (after using the `INITSYS` macro), or it can be stored manually by entering the hexadecimal values `08 00 30` into memory starting at location `FFF9` from *Handebug*.