Jump to content
IGNORED

Reading joysticks new to coleco programming


MrDave

Recommended Posts

To read the joystick I use the following wrapper methods:

CONTROLLER_INIT:  EQU $1105
CONTROLLER_SCAN:  EQU $1f76
DECODER:          EQU $1f79
POLLER:           EQU $1feb

; To be added together for CONTROLLER_MAP +0 (player 1),
; and +1 (player 2)
CONTROLLER_ENABLE:  EQU 80h
KEYPAD_ENABLE:      EQU 10h
ARM_BUTTON_ENABLE:  EQU 8
JOYSTICK_ENABLE:    EQU 2
FIRE_BUTTON_ENABLE: EQU 1

;
; Controller Table offsets
PLAYER1:    EQU 0 ; Settings (above)
PLAYER2:    EQU 1
FIRE1:      EQU 2 ; Fire button 1 (40h=yes, 0=no)
JOY1:       EQU 3 ; 1=N, 2=E, 4=S, 8=W, etc.
SPIN1:      EQU 4 ; counter
ARM1:       EQU 5 ; Arm button 1 (40h=yes, 0=no)
KEYPAD1:    EQU 6 ; 0-9, '*'=10, '#'=11
FIRE2:      EQU 7
JOY2:       EQU 8
SPIN2:      EQU 9
ARM2:       EQU 10
KEYPAD2:    EQU 11


; Test for the press of a joystick button (0 or 1)
; A = 255 - fire button pressed
JOYTST:
    LD A,(CONTROLLER_BUFFER+FIRE1)
    OR A
    JR Z,JOYTST2
    LD A,255
    RET
JOYTST2:
    LD A,(CONTROLLER_BUFFER+5)
    AND 040h
    RET Z
    LD A,255
    RET

; Test for a press of a keypad button
JOYPAD:
    LD A,(CONTROLLER_BUFFER+KEYPAD1)
    RET
;
; Test for the direction of joystick 0
; Result: A
JOYDIR:
       LD A,(CONTROLLER_BUFFER+JOY1)
       RET

CONTROLLER_BUFFER: DS 12 ; Pointer to hand controller input area

 

Before using you need to call CONTROLLER_INIT

	; Enable both joysticks, buttons, keypads
	LD	HL,09b9bh
	LD	(CONTROLLER_BUFFER),HL
	XOR A
	CALL CONTROLLER_INIT

 

And before your section of code where you want to read joystick inputs, call POLLER e.g.

	CALL POLLER
	CALL JOYDIR
	; A now has the joystick direction

 

Important notes:

- The CONTROLLER_BUFFER needs to be pointed to in your cartridge header e.g.

;
; Set ROM header
           ORG        8000h
;        --------------------------------------------
;           DB       0AAh,055h       ;Cartridge present:  Colecovision logo
           DB       055h,0AAh       ;Cartridge present:  skip logo, Colecovision logo
           DW       0000           ;Pointer to the sprite name table
           DW       0000           ;Pointer to the sprite order table
           DW       0000           ;Pointer to the working buffer for WR_SPR_NM_TBL
           DW       CONTROLLER_BUFFER ;Pointer to the hand controller input areas
           DW       START      ;Entry point to the user program
;****************************************************************

 

Make sure you also clear out the buffer before using it.

Link to comment
Share on other sites

5 minutes ago, MrDave said:

Thanks ! I am reading your book on kindle lol..

So do i need to clear buffer before each read ? Also the ld hl, 09b9bh is that just &9B9B ?

So no just clear the buffer once at start-up before you call CONTROLLER_INIT, then call POLLER and then one of the helper functions.

Link to comment
Share on other sites

2 minutes ago, MrDave said:

Also.. are there  hardcopy's of your books ?

Thanks

Cote Gamers have sold out of the spiral print edition, although I do have a small number of signed copies (here in OZ so post can be a bit steep due to the book being 1.1kgs - see my website).

 

I am going to do a re-edit (as with controllers especially there are a couple of discoveries to ensure your game works on all platforms i.e. Phoenix) and release a new edition which I will release as an Amazon Print on Demand version, they now have hard back as a print option.  I am working on another book at the moment though, so it will be a few months before I get that done.  Completely re-written version of the Sprite and Tile editor will be coming out as well.

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...