[Coco] Assembly Language Question
Little John
sales at gimechip.com
Fri Oct 1 15:31:14 EDT 2010
Okay, I am about to go nuts here:
I was attempting to create a SHOULD BE VERY SIMPLE routine to sample the joystick pots. Using cartesian X,Y coordinates (X=Column left/right, Y=Row up/down), I wanted X to be 0-31 (a simple divide by 2 of the pot values) and the Y to be 0-15 (a divide by 4 of the pot values). This would correspond to an X,Y position on the VDG screen (the memory address could be calculated as Y*32+X+$400)
But I can't get it to work right - under VCC or MESS. I tested the "algorithm" in BASIC first - it works. So I translated it to Assembly as:
0E00 00100 ORG $E00
015A 00110 POTVAL EQU $015A
015D 00120 RH EQU POTVAL+3
015C 00130 RV EQU POTVAL+2
015B 00140 LH EQU POTVAL+1
015A 00150 LV EQU POTVAL
A00A 00160 JOYIN EQU $A00A
0E00 AD 9F A00A 00170 START JSR [JOYIN]
0E04 74 015D 00180 LSR RH
0E07 74 015B 00190 LSR LH
0E0A 74 015C 00200 LSR RV
0E0D 74 015C 00210 LSR RV
0E10 74 015A 00220 LSR LV
0E13 74 015A 00230 LSR LV
0E16 1C AF 00240 ANDCC #$AF
0E18 39 00250 RTS
0E19 00260 DONE EQU *
0E00 00270 END START
00000 TOTAL ERRORS
Basically, this should call (indirectly) JOYIN whose address is stored in $A00A, with the values 0-63 being placed in the four joystick variables. An LSR is used to divide the H (X)values by 2. Two LSR's used to divide the V (Y) values by four. JOYIN Masks IRQ/FIRQ so the AND restores them and then we return with the adjusted values.
Using this BASIC program to test:
10 CLS
20 LOADM"JOY":A=&H015A
30 EXEC&HE00
40 PRINT at 0,"RIGHT X";PEEK(&H15D)
50 PRINT"RIGHT Y";PEEK(&H15C)
60 PRINT"LEFT X";PEEK(&H15B)
70 PRINT"LEFT Y";PEEK(&H15A)
80 GOTO30
AND IT DOESN'T WORK? I know I have overlooked something and that it must be something simple - I just don't know what - I'm pulling my hair out (well, what's left of it anyway)
When the BASIC program is RUN, moving the mouse UP/DOWN cycles the X values 0-31 - it should be moving left/right to cycle these values.
Moving left/right cycles the Y values 0-15 - it should be moving up down to cycle these values. Now I could fix this by swapping the operations in the assembly language - but what I need to understand is why it is failing to work as it is. It seems to be coded right judging by all the docs I've read and the fact that the BASIC test of the algorithm works as expected.
Could any of you guys point out to me what I've done wrong? It might save some of my hair. I've written some pretty complex Assembly Routines for the CoCo over the past few weeks and all work as expected - but this "should be simple" routine fails? Any ideas?
More information about the Coco
mailing list