Page 1 of 1

MGE-joy Sketcher

Posted: Tue Feb 18, 2025 11:30 pm
by ericomont
The TRS-80 Color Computer has, by nature, support for single button analog joysticks. Original USA COCOs have the famous black beauties' and the deluxe joystick. The deluxe was auto-centered while the beauty wasn't. Here they are:
Image

But here in Brazil we didn't have the original COCOs but, amongst many local versions, the CP-400s. It had its own non-centering joysticks, just like the black beauty, the original one. They were not as sturdy as the black beauty when it comes to materials so they happen to be a bit fragile on this time and age. Certainly not something one would take to a retro fest or even let others play around with it.

Enter the efforts of Mauricio Matte and Giovani Gualdi, two of the top notch Brazillian color computer users, and they came up with a nice solution, a modern analog joystick made based on the design of the CP-400 original ones, sturdy and made with quality materials. Here is the original and the new one:
Image

In possession of these two, thanks to the support I received from COCON and these dudes, I now have functional joysticks. It has long been my intention to produce software that takes advantage of the analog nature of them, it is something unique to this machine after all.

Re: MGE-joy Sketcher

Posted: Tue Feb 18, 2025 11:58 pm
by ericomont
Just in case one wonders what is a CP-400 and what it looks like, this is the second version, the one I currently own:
Image

You sure can see the design style match on its original joystick :)
So this thread is about testing the new joystick and see how it fares within ugBasic.

Enter MGE-joy Sketcher, an "etch a sketch" kind of tool made to precisely check the new and old analog joystick functionality.
The tool is very simple, it runs on a special non-standard resolution of 64x64 pixels, precisely the resolution of both joystick's axis.
The thing is more or less self explanatory, use the joystick to move the flashing cursor/pixel around, press button to lower the pen and start drawing, press again to raise it. Pressing "I" will cycle through pen color, "P" will do the same for paper color, "C" will clear the screen with the paper color, "T" will turn on/off the info HUD and "R" will get you back to the title. Here is the title with the instructions:
Image

Press button to start drawing, here other than the flashing cursor, on top HUD, you have the pen state (raised/lowered), X and Y coordinates, and a "I" character showing the ink and paper colors (not seen on this screenshot as I had them both green :) )
Image

Re: MGE-joy Sketcher

Posted: Wed Feb 19, 2025 12:29 am
by ericomont
This achieves the goal, to test the new joystick and also some of the ugBasic features.
The joystick responded wonderfully, much better than the original :)
Special thanks to Marco for fixing issues I found and the color computer community for chipping in ideas of possible solutions. You guys rock.

Finally, here is the commented code, binaries and disk files shall be on the RELEASE thread.

Code: Select all

'MGE JOY Sketcher v1.0
'Free hand analog joystick sketcher for the TRS-80 Color Computer
'Made by Erico for the Mauricio and GiovaniĀ“s modern new joystick

'---VARIABLES
x=32:y=32						:'Current pen position
w=32:z=32						:'Last pen position
a=0								:'Pen location canvas color 
i=1								:'Pen color 0-3 (yellow)
p=0								:'Paper color 0-3 (green)
pm=0							:'Pen mode 0-1 raised/lowered (raised)
t=0								:'Pen raised blinking timer
m=0								:'Color mode 0-1
h=1								:'Display HUD

'---BOOT
boot:
SCREEN #7						:'Set 64x64 resolution - color mode 0
p01 := LOAD IMAGE("TITLE.png")	:'Load title/instruction screen
PUT IMAGE p01 AT 0,0			:'Display it
WAIT FIRE						:'Press key or button to start
BELL 6,800
WAIT 400 MS						:'Wait a little bit
CLS								:'Clear the screen
pm=0							:'Raise pen

'--------------------------------------------------------------------LOOP
DO
tim=TIMER

x=JOYX(0):y=JOYY(0)	:'Get analog joystick values(-32 to 32) for each axis
x=x+31:y=y+31		:'Fix value ranges 0 to 63 for each axis

'---RAISE OR LOWER PEN
IF JFIRE(0)=TRUE THEN:						:'Is joystick button pressed?
	IF pm=0 THEN:
		pm=1:BELL 40,300:BELL 22,300		:'Lower pen and make some noise! 
	ELSE:
		pm=0:BELL 32,300:BELL 50,300		:'Raise pen and make some noise!
	ENDIF
	a=i										:'Set pen color to canvas color
	WAIT 100 MS								:'Wait a little bit
ENDIF

'---MOVE AND DRAW WITH PEN
IF pm=0 THEN:				:'If the pen is raised
	IF x<>w OR y<>z THEN:		:'Is new location different than the last one?
		PEN a:POINT AT(w,z)		:'Erase last location with recorded canvas color
		a=POINT(x,y)			:'Record current pen location canvas color
		PEN i					:'Set pen color
		IF a=i THEN:			:'If color equal to background choose another
			PEN a+1
			IF a=3 THEN PEN 0	:'Use 0 if pen color equals canvas color	
		ENDIF
		POINT AT(x,y)			:'Plot current pen
	ELSE:							:'New location same as last
		IF t=0 THEN:				:'Blink pen
			PEN i:t=1				:'Set first pen color 
		ELSE
			PEN a					:'Set pen second color
			IF a=i THEN:			:'If color equal to background choose another
				PEN a+1
				IF a=3 THEN PEN 0	:'Use 0 if pen color equals canvas color
			ENDIF
			t=0						:'reset blink timer
		ENDIF
		POINT AT(x,y)				:'Plot pen
	ENDIF
ELSE:						:'If the pen is lowered
	LINE w,z TO x,y,i			:'Draw line between current and last locations
ENDIF
w=x:z=y						:'Update last pen position to current one

'---USER INTERFACE
If KEY PRESSED(KEY I) THEN:						:'Press I to cicle pen color	
	i=i+1:BELL 22,600
	IF i=4 THEN i=0
ENDIF
If KEY PRESSED(KEY P) THEN:						:'Press P to cicle paper color
	p=p+1:BELL 22,600
	IF p=4 THEN p=0
ENDIF
If KEY PRESSED(KEY C) THEN:						:'Press C to clear screen
	LOCATE 0,0: PAPER p
	PRINT"                                ";
	PRINT"                                 ";
	a=POINT(x,y)
	BELL 22,600
ENDIF
If KEY PRESSED(KEY R) THEN:						:'Press R to reset to title
	BELL 12,600
	GOTO boot
ENDIF
IF KEY PRESSED(KEY T) THEN:						:'Press T for HUD on/off
	IF h=0 THEN:
		h=1
	ELSE:
		h=0:LOCATE 0,0
		PRINT "        "; 
	ENDIF
	BELL 22,600
ENDIF

'---HUD
IF h=1 THEN:
	LOCATE 0,0:PAPER 2:PEN 1					:'Print raised/lowered pen icon
	IF pm=0 THEN:PRINT"^";:ELSE:PRINT"*";:ENDIF
	LOCATE 1,0:PAPER 0:PEN 3:PRINT x;" ";		:'Print pen x location
	LOCATE 4,0:PRINT y;" ";						:'Print pen y location
	LOCATE 7,0:PAPER p:PEN i:PRINT"I";			:'Print ink and paper icon
ENDIF

LOOP

Re: MGE-joy Sketcher

Posted: Wed Feb 19, 2025 12:40 am
by ericomont
....also, MGE stands for Mauricio Giovani Erico :D
Check this thread for BIN, DSK and SOURCE:
viewtopic.php?t=176