Vectrex System - Hardware and Periphery Vextrex Games - Modules and Cartridges Vectrex History The last Vectrex news... The museum´s shop Vectrex Links - Info and Collectors pages
Vectrex Programming TOC

Joystick/Button input

This is going to be the last chapter, and as the chapters befor, no in depth view and programming information will be given. I'll only tell you about the BIOS routines. And I don't think any sane person will need any more information, as I allready mentioned in my babblings about sound, the joypads are (indirectly) connected to the PSG soundchip, which in turn can only be accessed using some werid pokes to the VIA chip. So I dearly recommed any programmer to only use the available functions. These functions are:

Joy_Analog ($F1F5)
Joy_Digital ($F1F8)
Read_Btns_Mask ($F1B4)
Read_Btns ($F1BA)
All of these routines require the DP register set to $D0! Furthermore there are some very interesting BIOS RAM locations, here is a list of them, but read on for some more information about them:
Vec_Btn_State ($C80F) Current state of all joystick buttons
Vec_Prev_Btns ($C810) Previous state of all joystick buttons
Vec_Buttons ($C811) Current toggle state of all buttons
Vec_Button_1_1 ($C812) Current toggle state of stick 1 button 1
Vec_Button_1_2 ($C813) Current toggle state of stick 1 button 2
Vec_Button_1_3 ($C814) Current toggle state of stick 1 button 3
Vec_Button_1_4 ($C815) Current toggle state of stick 1 button 4
Vec_Button_2_1 ($C816) Current toggle state of stick 2 button 1
Vec_Button_2_2 ($C817) Current toggle state of stick 2 button 2
Vec_Button_2_3 ($C818) Current toggle state of stick 2 button 3
Vec_Button_2_4 ($C819) Current toggle state of stick 2 button 4
Vec_Joy_Resltn ($C81A) Joystick A/D resolution ($80=min $00=max)
Vec_Joy_1_X ($C81B) Joystick 1 left/right
Vec_Joy_1_Y ($C81C) Joystick 1 up/down
Vec_Joy_2_X ($C81D) Joystick 2 left/right
Vec_Joy_2_Y ($C81E) Joystick 2 up/down
Vec_Joy_Mux ($C81F) Joystick enable/mux flags (4 bytes)
Vec_Joy_Mux_1_X ($C81F) Joystick 1 X enable/mux flag (=1)
Vec_Joy_Mux_1_Y ($C820) Joystick 1 Y enable/mux flag (=3)
Vec_Joy_Mux_2_X ($C821) Joystick 2 X enable/mux flag (=5)
Vec_Joy_Mux_2_Y ($C822) Joystick 2 Y enable/mux flag (=7)

Vec_Misc_Count ($C823) misc counter/flag byte, zero when not in use

One small note in advance, in order for the joypad routines to work correctly, you must again asure that the Vec_Misc_Count ($C823) BIOS RAM location is zero, since it is used for analog testing. As said befor, if you don't change that variable somewhere, than everything is ok, since BIOS functions allways return leaving that location zero.

Again I will not describe all functions and all variables, only two actually, probably the two you'll need most. The other functions can again be easily worked out by looking at the appropriate BIOS dissassembly (where you can actually find everything (nearly) I say in this document), or Appendix A.

Let us first do the most easy things, as usual. Let us have a look at the buttons. Here is a small example:

button1.asm

The above function calls the Read_Btns ($F1BA) function. This function does a couple of things. But the only thing we use in the above example is the information given to us in register A. In that register a button transition information is given. That means a bit is set at a button specific position, if it's state has changed. But only half the transition is registered, the transition from unpressed to pressed. If such a transition occured than for the next call of Read_Btns the appropriate bit will be set. Most of the time that little information is enough. Especially if you don't want continues fire or the like. I guess I don't have to go through the program line by line, as I did befor, since (pardon me) it IS fairly obvious. The Read_Btns function has some other uses (for an exact describtion look at the disassembled ROM listing or Appendix A), further down you will find a program that makes use of the RAM locations mentioned above, that are set to the current button state by the Read_Btns function. The function does following other things:

Vec_Buttons ($C811) Current toggle state of all buttons
Contains the same information as register A.

Vec_Btn_State ($C80F) Current state of all joystick buttons
Contains a bitmap whether a button is pressed (1) or not (0).

Vec_Prev_Btns ($C810) Previous state of all joystick buttons
Contains a bitmap whether a button was pressed (1) or not (0) befor the function call.

Vec_Button_1_1 ($C812) Current toggle state of stick 1 button 1
Vec_Button_1_2 ($C813) Current toggle state of stick 1 button 2
Vec_Button_1_3 ($C814) Current toggle state of stick 1 button 3
Vec_Button_1_4 ($C815) Current toggle state of stick 1 button 4
Vec_Button_2_1 ($C816) Current toggle state of stick 2 button 1
Vec_Button_2_2 ($C817) Current toggle state of stick 2 button 2
Vec_Button_2_3 ($C818) Current toggle state of stick 2 button 3
Vec_Button_2_4 ($C819) Current toggle state of stick 2 button 4

The bitmap used in all above BIOS RAM locations is as in the above program:
joystick 1:
button 1: $01
button 2: $02
button 3: $04
button 4: $08

joystick 2:
button 1: $10
button 2: $20
button 3: $40
button 4: $80

With the that information we can easily change our above program to print a steady message whether a button is currently pressed or not. From the at least two different approaches we take the (IMHO) easier one:

button2.asm

I think we pretty much exhausted the possibilities of the buttons with the above two examples (leave alone the masked button requests, but they are not really that different) let us go on to the joystick(s).

As you have seen above there are two functions for joystick information gathering. I will only explain a bit of Joy_Digital ($F1F8), since analog is (again IMHO) not all that usefull, and takes considerable time to calculate and is even a bit unstable.

Some preliminaries first. When you program a game you'll probably at one stage know what kind of joystick routine you need (one or two joysticks, digital or analog), once you know that, you should set up the BIOS joystick routines for your needs, because (and I really mean it) these routines are cycle wasters, and every bit they have to calculate to much is really a waste. There are the following BIOS RAM locations:

Vec_Joy_Mux_1_X ($C81F) Joystick 1 X enable/mux flag (=1)
Vec_Joy_Mux_1_Y ($C820) Joystick 1 Y enable/mux flag (=3)
Vec_Joy_Mux_2_X ($C821) Joystick 2 X enable/mux flag (=5)
Vec_Joy_Mux_2_Y ($C822) Joystick 2 Y enable/mux flag (=7)
Into these you should pass the information what you want to know. 0 means not interested and the 'flag' numbers mean that you are interested. In the example program below we are only interested in joystick one, but both X and Y position.

joystick1.asm

The above example is (hopefully understandable) again straight forward. A simple example for a joypad inquiry. The above tested BIOS RAM locations contain allways the current position of the joypad (current means last set by the Joy_Digital function). Negative values stand for left/down, positive for right/up and zero for no movement detected. Following are again the BIOS RAM locations, where these will be set, both for joypad 1 and joypad 2.

Vec_Joy_1_X ($C81B) Joystick 1 left/right
Vec_Joy_1_Y ($C81C) Joystick 1 up/down
Vec_Joy_2_X ($C81D) Joystick 2 left/right
Vec_Joy_2_Y ($C81E) Joystick 2 up/down

Next page Last Page

Vectrex Programming TOC

Back to Vectrex Programming Docs Index
 
 

 


Vectrex Last Minute RSS

Related Links and sources

Please note

The Museums Staff can not answer any programming related questions. If you have extra info about this page, if you noticed errors, please help to maintain this site. Please send us the information you have.

 

 

Back to Programming Docs Index
 
 

vectrexmuseum.com