From c0d8021fd5795b9ed58c11dbf9a376bdbcbc367a Mon Sep 17 00:00:00 2001 From: mrdudz Date: Tue, 6 Mar 2018 23:36:11 +0100 Subject: [PATCH 1/4] add comment on linking, tweak a bit for easier debugging --- testcode/lib/joy-test.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/testcode/lib/joy-test.c b/testcode/lib/joy-test.c index fdd83bb4e..51cbb53e2 100644 --- a/testcode/lib/joy-test.c +++ b/testcode/lib/joy-test.c @@ -5,7 +5,6 @@ #include #include - #ifdef JOYSTICK_DRIVER /* A statically linked driver was named on the compiler's command line. @@ -13,6 +12,22 @@ */ # undef DYN_DRV # define DYN_DRV 0 + +/* + * link existing drivers like this: + * + * cl65 -DJOYSTICK_DRIVER=c64_hitjoy_joy -o joy-test.prg joy-test.c + * + * for testing a new driver you will have to uncomment the define below, and + * link your driver like this: + * + * co65 ../../target/c64/drv/joy/c64-hitjoy.joy -o hitjoy.s --code-label _hitjoy + * cl65 -DJOYSTICK_DRIVER=hitjoy -o joy-test.prg joy-test.c hitjoy.s + * +*/ + +/* extern char JOYSTICK_DRIVER; */ + #else /* Use a dynamically loaded driver, by default. */ @@ -27,13 +42,16 @@ int main (void) unsigned char j; unsigned char count; unsigned char i; + unsigned char Res; + + clrscr (); #if DYN_DRV - unsigned char Res = joy_load_driver (joy_stddrv); + Res = joy_load_driver (joy_stddrv); #elif defined(JOYSTICK_DRIVER) - unsigned char Res = joy_install (&JOYSTICK_DRIVER); + Res = joy_install (&JOYSTICK_DRIVER); #else - unsigned char Res = joy_install (&joy_static_stddrv); + Res = joy_install (&joy_static_stddrv); #endif if (Res != JOY_ERR_OK) { @@ -44,7 +62,6 @@ int main (void) exit (EXIT_FAILURE); } - clrscr (); count = joy_count (); #if defined(__ATARI5200__) || defined(__CREATIVISION__) cprintf ("JOYSTICKS: %d", count); @@ -56,21 +73,21 @@ int main (void) gotoxy (0, i+1); j = joy_read (i); #if defined(__ATARI5200__) || defined(__CREATIVISION__) - cprintf ("%1d:%-3s%-3s%-3s%-3s%-3s%-3s", + cprintf ("%1d:%-3s%-3s%-3s%-3s%-3s %02x", i, JOY_UP(j)? " U " : " - ", JOY_DOWN(j)? " D " : " - ", JOY_LEFT(j)? " L " : " - ", JOY_RIGHT(j)? " R " : " - ", - JOY_BTN_1(j)? " 1 " : " - "); + JOY_BTN_1(j)? " 1 " : " - ", j); #else - cprintf ("%2d: %-6s%-6s%-6s%-6s%-6s%-6s", + cprintf ("%2d: %-6s%-6s%-6s%-6s%-6s %02x", i, JOY_UP(j)? " up " : " ---- ", JOY_DOWN(j)? " down " : " ---- ", JOY_LEFT(j)? " left " : " ---- ", JOY_RIGHT(j)? "right " : " ---- ", - JOY_BTN_1(j)? "button" : " ---- "); + JOY_BTN_1(j)? "button" : " ---- ", j); #endif } } From 38fedfd78bdc81032495365e7cd76665d7b3b14f Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 7 Mar 2018 00:19:14 +0100 Subject: [PATCH 2/4] also show pressed key, so we can verify keyboard works with the joystick driver --- testcode/lib/joy-test.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/testcode/lib/joy-test.c b/testcode/lib/joy-test.c index 51cbb53e2..167534137 100644 --- a/testcode/lib/joy-test.c +++ b/testcode/lib/joy-test.c @@ -43,6 +43,7 @@ int main (void) unsigned char count; unsigned char i; unsigned char Res; + unsigned char ch, kb; clrscr (); @@ -90,6 +91,14 @@ int main (void) JOY_BTN_1(j)? "button" : " ---- ", j); #endif } + + /* show pressed key, so we can verify keyboard is working */ + kb = kbhit(); + ch = kb ? cgetc() : ' '; + gotoxy (1, i+2); + revers(kb); + cprintf("kbd: %c", ch); + revers(0); } return 0; } From 3afbed48e068f5c467d122229c80c48fe21063c4 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 7 Mar 2018 00:20:42 +0100 Subject: [PATCH 3/4] tweak driver to no more use IRQ --- libsrc/c64/joy/c64-hitjoy.s | 48 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/libsrc/c64/joy/c64-hitjoy.s b/libsrc/c64/joy/c64-hitjoy.s index 9f6c0b4dd..3b4a0b909 100644 --- a/libsrc/c64/joy/c64-hitjoy.s +++ b/libsrc/c64/joy/c64-hitjoy.s @@ -73,13 +73,22 @@ UNINSTALL: rts ; ------------------------------------------------------------------------ -; IRQ entry point. Is called from the C layer as a subroutine in the -; interrupt. The routine MUST return carry set if the interrupt has been -; 'handled' - which means that the interrupt source is gone. Otherwise it -; MUST return carry clear. +; COUNT: Return the total number of available joysticks in a/x. +; -IRQ: ; cia 2 setup +COUNT: lda #JOY_COUNT + rts +; ------------------------------------------------------------------------ +; READ: Read a particular joystick passed in A. +; + +readadapter: + + sei + + ; cia 2 setup ldy #$00 ; port b direction sty $dd03 ; => input @@ -143,32 +152,24 @@ IRQ: ; cia 2 setup sta temp4 fire: - ; Default Value: $40/64 on PAL - ; $42/66 on NTSC + ; FIXME: to be really 100% correct this should restore the correct timer + ; values for the respective machine (PAL: $4025, NTSC: $4295) + ; however, this should hardly be a problem in a real world program + lda #$41 sta $dc05 - ; Default Value: $25/37 on PAL - ; $95/149 on NTSC lda #0 sta $dc04 - ; We do never "handle" the interrupt, we use it just as a timer. - clc + cli rts -; ------------------------------------------------------------------------ -; COUNT: Return the total number of available joysticks in a/x. -; +READ: + pha + jsr readadapter + pla -COUNT: lda #JOY_COUNT - rts - -; ------------------------------------------------------------------------ -; READ: Read a particular joystick passed in A. -; - -READ: tax ; Joystick number into X + tax ; Joystick number into X bne joy2 ; Read joystick 1 @@ -214,4 +215,3 @@ joy4: lda temp4 eor #$1F ldx #0 rts - From 85e480db3d0623c5b313c5eb3c5976cc3d6f89d7 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Thu, 8 Mar 2018 04:05:10 +0100 Subject: [PATCH 4/4] style fixes --- testcode/lib/joy-test.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/testcode/lib/joy-test.c b/testcode/lib/joy-test.c index 167534137..3d584bf9d 100644 --- a/testcode/lib/joy-test.c +++ b/testcode/lib/joy-test.c @@ -14,16 +14,16 @@ # define DYN_DRV 0 /* - * link existing drivers like this: - * - * cl65 -DJOYSTICK_DRIVER=c64_hitjoy_joy -o joy-test.prg joy-test.c - * - * for testing a new driver you will have to uncomment the define below, and - * link your driver like this: - * - * co65 ../../target/c64/drv/joy/c64-hitjoy.joy -o hitjoy.s --code-label _hitjoy - * cl65 -DJOYSTICK_DRIVER=hitjoy -o joy-test.prg joy-test.c hitjoy.s - * +** link existing drivers like this: +** +** cl65 -DJOYSTICK_DRIVER=c64_hitjoy_joy -o joy-test.prg joy-test.c +** +** for testing a new driver you will have to uncomment the define below, and +** link your driver like this: +** +** co65 ../../target/c64/drv/joy/c64-hitjoy.joy -o hitjoy.s --code-label _hitjoy +** cl65 -DJOYSTICK_DRIVER=hitjoy -o joy-test.prg joy-test.c hitjoy.s +** */ /* extern char JOYSTICK_DRIVER; */ @@ -93,12 +93,12 @@ int main (void) } /* show pressed key, so we can verify keyboard is working */ - kb = kbhit(); - ch = kb ? cgetc() : ' '; + kb = kbhit (); + ch = kb ? cgetc () : ' '; gotoxy (1, i+2); - revers(kb); - cprintf("kbd: %c", ch); - revers(0); + revers (kb); + cprintf ("kbd: %c", ch); + revers (0); } return 0; }