CPCWiki forum

General Category => Technical support - Hardware related => Topic started by: m_dr_m on 10:38, 09 December 23

Title: How to make an optic pen?
Post by: m_dr_m on 10:38, 09 December 23
Hello, given modern modernity, is there a simpler way to make an optic pen than Dart Light Pen? (https://www.cpcwiki.eu/index.php/Dart_Light_Pen)
I'm also willing to buy one already made.

Goal: exploit it for incoming artistic tools.
Title: Re: How to make an optic pen?
Post by: SerErris on 19:10, 10 December 23
The light pen itself just consists out of a light sensitive transistor and some logic gates. So Potentially you can reverse engineer the dark light pen PCB with a PLA or CPLD. I have not really looked into the logic of the dark light pen as the pictures we have here on CPC wiki of the PCB is lacking two things:

1. The Backside of the PCB is pretty blurry
2. You cannot identify the Transistors on the PCB.

Also the characteristics of the Fotosensitive transistor inside of the PEN is unknown. 

I think it is much simpler to just create on from scratch. But never done that. Also I could not find any projekt to create a new one.
Title: Re: How to make an optic pen?
Post by: SerErris on 19:23, 10 December 23
Okay,

the simples setup should be to connect a light pen like this one to the expansion port:

https://www.atariarchives.org/ecp/chapter_6.php

Instead of connecting it to a joystick port, you connect the LightPen Output Gate to the L.PEN pin and the Switch could be connected to NMI or something alike, so that you can press a button and let a software react on the interrupt and read the CRTS L.PEN registers.

Obviously I would use a modern fotoresistor that has a range from 400nm to 1000nm to be able to recognize the signale better. 
Title: Re: How to make an optic pen?
Post by: GUNHED on 22:11, 12 December 23
My first lightpen (still have it) was made out of:
- Resistor
- Transistor
- Optical 'sensor'

How to do it was written in some computer magazin back the day.
Title: Re: How to make an optic pen?
Post by: Brocky on 23:25, 12 December 23
from what ive read, using the light pen pin on the expansion port requires very little hardware
just a photodiode (a reverse LED!)..and maybe a resistor to keep the levels low...
when the electron beam from the monitor hits the photodiode it generates a signal to the CRTC, which is doing all the timing and puts the location of the beam hit into a register... 
your draw function works just by reading that register out and plotting the location on screen...
Title: Re: How to make an optic pen?
Post by: Titi on 00:38, 13 December 23
https://cpcrulez.fr/hardware_montage_8x-realisez_votre_crayon_optique.htm
Title: Re: How to make an optic pen?
Post by: GUNHED on 14:56, 13 December 23
The 6128plus offers that small nice port to connect a light pen anyway.  :)
Title: Re: How to make an optic pen?
Post by: Bryce on 18:57, 13 December 23
Quote from: GUNHED on 14:56, 13 December 23The 6128plus offers that small nice port to connect a light pen anyway.  :)

Yes, but it wasn't compatible with the pens that worked on the classic CPC as far as I know, such as the DK'Tronics pen. The circuitry of the DK device is easy to recreate and works with the DK software and other programmes too (including your own FutureOS I believe).

Bryce.
Title: Re: How to make an optic pen?
Post by: GUNHED on 15:30, 14 December 23
No, it's not compatible. But who cares?
The idea was to have a small port instead to use the large 50 pin expansion connector. The needed signals are all there (see 6128plus manual).

Here I got three kinds of Light Pens (no dk'tronics though), all work fine with CPC6128 (Expansion port) and 6128plus (Light-Pen-Port). :-)

Some unusual light pens used different and uncommon techniques, they still need to be connected to the expansion port. However, they are not better - just better protected against 'hardware piracy' if you know what I mean.
Title: Re: How to make an optic pen?
Post by: SkulleateR on 19:29, 14 December 23
There once was a simple pcb posted either in "CPC Internatoinal" or "CPC Magazine" back in the days together with a REALLY simple Basic Code but it worked, I built that one (but I really don´t know where I put it) ... if someone finds that article please leave a note here :)
Title: Re: How to make an optic pen?
Post by: SerErris on 23:34, 14 December 23
Also the lightpen on the 50pin port has the fantastic benefit of it getting directly attached to the CRTC and you can then just read the CRTC lightpen register to understand where it actually has hit the screen.

So I think it cannot get better than that.

There also exist Joystickport versions, but you then have to do the calculation yourself and also time will go by until you read it, and I am not sure how it should work as the joystick port is only getting checked every 1/50s second - that would be just not helpful.

If you want to mod your case, you can just put a new port in the case (4 Pins are enough), with 12V, GND and then one line to the CRTC LightPen and one line to NMI.

But in reality that does not make to much sense if the exact same thing is anyhow availble without any mods on the expansion port.
Title: Re: How to make an optic pen?
Post by: Titi on 08:32, 15 December 23
https://www.ebay.fr/itm/285607463620?_trkparms=amclksrc%3DITM%26aid%3D777008%26algo%3DPERSONAL.TOPIC%26ao%3D1%26asc%3D20221115143302%26meid%3Dad1ab208fad94649baba156703c2b60b%26pid%3D101613%26rk%3D1%26rkt%3D1%26mehot%3Dnone%26itm%3D285607463620%26pmt%3D0%26noa%3D1%26pg%3D4375194%26algv%3DRecentlyViewedItemsV2Mobile%26brand%3DAmstrad&_trksid=p4375194.c101613.m146925&_trkparms=parentrq%3A6c60cdcc18c0aaf606d5b02fffff7a23%7Cpageci%3A98f529f7-9b1b-11ee-82e1-6af13ecd6710%7Ciid%3A1%7Cvlpname%3Avlp_homepage

150 euros 😕😕😕
Title: Re: How to make an optic pen?
Post by: SerErris on 09:21, 15 December 23
And I am not sure how this is actually working via Joystickport. There is no interrupt source and I am not sure how you actually check it? 

Run a routine every µsec to get the actual pixel? That must have poor resulution. Even every line will be painful. 

Anyone can share light in it how this joystick port based version would even work?
Title: Re: How to make an optic pen?
Post by: SerErris on 11:59, 15 December 23
Quote from: SkulleateR on 19:29, 14 December 23There once was a simple pcb posted either in "CPC Internatoinal" or "CPC Magazine" back in the days together with a REALLY simple Basic Code but it worked, I built that one (but I really don´t know where I put it) ... if someone finds that article please leave a note here :)
https://archive.org/details/06_Schneider_CPC_International_1985-08
Title: Re: How to make an optic pen?
Post by: SkulleateR on 12:32, 15 December 23
Quote from: SerErris on 11:59, 15 December 23
Quote from: SkulleateR on 19:29, 14 December 23There once was a simple pcb posted either in "CPC Internatoinal" or "CPC Magazine" back in the days together with a REALLY simple Basic Code but it worked, I built that one (but I really don´t know where I put it) ... if someone finds that article please leave a note here :)
https://archive.org/details/06_Schneider_CPC_International_1985-08

Thanks :) Not the one with the PCB and the Basic listing but a nice addition ...
Title: Re: How to make an optic pen?
Post by: dodogildo on 14:32, 15 December 23
This project from Amstrad Magazine #8 looks pretty cool. I wonder if anybody tried it before.
Title: Re: How to make an optic pen?
Post by: GUNHED on 17:06, 17 December 23
Quote from: SkulleateR on 19:29, 14 December 23There once was a simple pcb posted either in "CPC Internatoinal" or "CPC Magazine" back in the days together with a REALLY simple Basic Code but it worked, I built that one (but I really don´t know where I put it) ... if someone finds that article please leave a note here :)
I have that one too. Works great (as far as technology allows it of course).
Here is the wiki entry: https://www.cpcwiki.eu/index.php/Happy_Computer_Light_Pen
Title: Re: How to make an optic pen?
Post by: Brocky on 13:53, 18 December 23
currently testing a photodiode connected to an arduinos analog input, testing i can actually detect the electron beam, before writing a small sketch that will output a signal on a digital pin when the beam is detected and hooking up to the lightpen pin (and ground) on the CPC..

only doing it with an arduino coz i dont have any transistors/opamps on hand!
Title: Re: How to make an optic pen?
Post by: SerErris on 14:39, 18 December 23
I think the main task will be to get it accurate enough. From the CRTC you only get the character position AFAIK.

But still very interested in your experiments.
Title: Re: How to make an optic pen?
Post by: Brocky on 15:19, 18 December 23
im detecting something.. but stray light is being a bit of an issue... ive put the photodiode into an old pen and have it recessed so that only light from the monitor will get in...

im guessing, that a button will be required to "activate" the lightpen when its needed... so its not constantly spamming the CRTC from stray light...

for reference, heres some info from the MC6845 datasheet...

Light Pen Strobe (LPSTB) - A low-to-high transition on this high-impedance TTL/ MOS-compatible input latches the current Refresh Address In the light pen register. The latching of the refresh address is Internally synchronized to the character clock (CLK)
Light Pen Register (R16-H, R17-L) - This 14-bit read-only register pair captures the refresh address output by the CRTC on the positive edge of a pulse input to the LPSTB pin. It consists of an 8-bit low order (MA0-MA7) register and a 6-bit high order (MA8-MA 13) register. Since the light pen pulse is asynchronous with respect to refresh address timing an internal synchronizer is designed into the CRTC. Due to delays in this circuit, the value of R16 and R17 will need to be corrected in software. Figure 16 shows an interrupt driven approach although a polling routine could be used.

and interestingly....

Note that the LPSTB input may be used to support additional system functions other than a light pen. A digital-to-analog converter (DAC) and comparator could be configured to use the refresh addresses as a reference to a DAC composed of a resistive adder network connected to a comparator. The output of the comparator would generate the LPSTB input signifying a match between the refresh address analog level and the unknown voltage. The light-pen strobe input could also be used as a character strobe to allow the CRTC refresh addresses to decode a keyboard matrix. Debouncing would need to be done in software
Title: Re: How to make an optic pen?
Post by: Brocky on 15:54, 18 December 23
the UM6845 datasheet says When the LPEN pin is changed from low to high, the registers get stored on the falling edge of the next CLK... 
so it seems there are even more differences between the different CRTC types!
Title: Re: How to make an optic pen?
Post by: GUNHED on 17:06, 18 December 23
Yes, some CRTC versions work with the usual (= the way Amstrad provides signals) light pens, but some CRTCs don't. There are different kinds.
Title: Re: How to make an optic pen?
Post by: darkhalf on 21:22, 18 December 23
The above seems to read the same to me for both, also noting the diagrams (Page 5-29)
https://datasheetspdf.com/pdf-file/544758/UMC/UM6845RB/1 (https://datasheetspdf.com/pdf-file/544758/UMC/UM6845RB/1)

Both communicate:
LPEN signal Low -> High triggers loading into the Ma0-Ma13 positions, which the contents of are available on next falling CCLK line (High -> Low). I'm not seeing the difference here?

I got one of the joystick port Amstrad ones but not sure is really available for it apart from what came on tape.

Would like to reverse engineer the Dart one so that we have more software avaiable. Unsure about all the extra logic chips on there, and can think it could only be used for some memory mapping decoding
Title: Re: How to make an optic pen?
Post by: Brocky on 02:59, 19 December 23
Quote from: darkhalf on 21:22, 18 December 23The above seems to read the same to me for both, also noting the diagrams (Page 5-29)
https://datasheetspdf.com/pdf-file/544758/UMC/UM6845RB/1 (https://datasheetspdf.com/pdf-file/544758/UMC/UM6845RB/1)

Both communicate:
LPEN signal Low -> High triggers loading into the Ma0-Ma13 positions, which the contents of are available on next falling CCLK line (High -> Low). I'm not seeing the difference here?

I got one of the joystick port Amstrad ones but not sure is really available for it apart from what came on tape.

Would like to reverse engineer the Dart one so that we have more software avaiable. Unsure about all the extra logic chips on there, and can think it could only be used for some memory mapping decoding

i was comparing CRTC type 0 and type 2.... looks like you compaired type 0 and type 1 (HD6845S and UM6845 are type 0, UM6845R is type 1, MC6845 is type 2).

the difference im seeing is type 2 puts the Refresh Address on the registers on the rising edge of LPEN signal, type 0 and it seems type 1 only put it on the register at the falling edge of the next CLK.

bit of a moot point really... as theres not that many type 2s around AFAIK... majority are type 0 and 1s...(correct me if im wrong!)
Title: Re: How to make an optic pen?
Post by: darkhalf on 08:27, 19 December 23
Quotelooks like you compaired type 0 and type 1
Was looking at the MC6845 you mentioned (Type 2) as I was curious of the differences

Figure 4 of the datasheet I have shows  LPSTB (LPEN) signal going high and clocking in the Refresh Memory Address into the register, but the register data is not valid until tLPD1 has expired (on the CLK signal going low). So effectively it looks like it should function the same as the other two types of CRT

Mute point as you mention, and also the processor still needs to read the register, which is many clock cycles later

Title: Re: How to make an optic pen?
Post by: Brocky on 15:26, 19 December 23
SMH.. youre right darkhalf, i didnt look at the timing diagrams!  :picard:

i still wonder if a pure digital signal is needed to trigger it, im measuring <1.8v when against the screen (phosphor glow), and over 2v when the electron beam hits, and clamped to 5v max. i guess 1.8v maybe to high to trigger it back to a low tho... altho an interrupter switch/button on the photodiode line itself would let the voltage drop to 0v.. (press button to allow the voltage through the photodiode)

i currently have the arduino sketch reading the voltage value via an analog input with limit clamp on the low side... it would be quite easy to use force a digital low when clamped below 2v and digital high when > 2v, but it would be really nice to use less hardware!
Title: Re: How to make an optic pen?
Post by: darkhalf on 13:40, 26 December 23
I would be using something similar that light pen circuit that dodogildo posted. Transistor would  control logic levels. They use an NPN and photo transistor.  No option for variable adjustment in that circuit. However something doesn't look right in the schematics so will need to check it over. 

Would like to make my current Amstrad pen trigger the LPEN instead of joystick port

Checked out parts on the Dart circuit board and its got 74 series logic chips including shifters, counters etc on it. Fair bit of stuff. Looks like standard NPN transistors
Title: Re: How to make an optic pen?
Post by: darkhalf on 07:24, 27 December 23
Attached is an 'enhanced' version of the DK'Tronics light pen circuit and some traced out schematics. Photo resistor goes via a transistor with various resistors to the LPEN input on the expansion port

The other part is the 27C128 EPROM which uses 74LS27 to NOR the inputs (/IORQ, /WR) and maybe A8? Some of the traces are impossible to track without the actual board.

Seems to then trigger a flipflop along with A15 via 74LS74 which enables ROMDIS and /CE similar to the other external ROM boards schematics I've looked at today. The D0-D3 lines are configurable via jumper holes in the middle of the board. Looks like D2 might be the only one enabled for this ROM. From the wiki page:
Quote
    A15=0 doesnt't trigger the Gate Array (which would also require A14=1)A13=0 does trigger Upper ROM Bank Number

So next step is to load the DK'Tronics ROM from a normal ROM expansion board

https://www.cpcwiki.eu/index.php/Dk%27tronics_Lightpen (https://www.cpcwiki.eu/index.php/Dk'tronics_Lightpen)

Then try the ROM software to write/read #BC00/#BF00 as #1C00/#1F00 using the Amstrad Magazine #8 pen
Title: Re: How to make an optic pen?
Post by: darkhalf on 08:56, 27 December 23
Okay so here is the Amstrad LP-1 lightpen inside
https://www.cpcwiki.eu/index.php/Amstrad_LP-1_light_pen (https://www.cpcwiki.eu/index.php/Amstrad_LP-1_light_pen)

As you can see it is just a photo diode with a 3.3K resistor between the legs inside a plastic case

Pin 2 JOY DOWN (white) is the light sensor output
QuoteKeyboard.Row9.Bit1 (aka Joystick Down) (0=Light, 1=No Light)

Pin 8 COMMON (red) is the ground
QuoteKeyboard.Row9 is constantly held LOW during lightpen access
(AY) PSG.Ext.PortA configured as inputs would pickup the corresponding column for the Joy Down input

I've had this for a while (got it from a friend) but not really used it much. The included software I've converted to DSK and loaded up. English Manual would be helpful, but the CPC wiki one was French only. I've converted it OCR and then google translate through it. Output is somewhat readable

The software uses square boxes to let you select through menus. Screen needs to be colour and brightness up. If your flyback isn't putting out enough brightness - it will not work

Basically to draw anything with this pen, you have to press SPACE to get the screen to flash white. It then grabs the current cursor point. Then you have to move the pen to the next location, and SPACE again to get the next point. It takes several seconds to do each point drawing with this method and is very cumbersome.
Title: Re: How to make an optic pen?
Post by: darkhalf on 12:20, 27 December 23
QuoteAlso the lightpen on the 50pin port has the fantastic benefit of it getting directly attached to the CRTC and you can then just read the CRTC lightpen register to understand where it actually has hit the screen. So I think it cannot get better than that
CRTC only can measure at character positions. This is the DK'Tronics and other implementations. Poll the CRTC to get the position and convert to X,Y

QuoteThere also exist Joystickport versions, but you then have to do the calculation yourself and also time will go by until you read it, and I am not sure how it should work as the joystick port is only getting checked every 1/50s second
This is the Trojan/Amstrad Joystick implementation. Needs screen to be 'white' to calculate the location in software from what I've seen so far. Can calculate pixels but there is a longer delay in calcualting. There is code for the LP-1 on CPCwiki which explains how to use it

Quotehttps://archive.org/details/06_Schneider_CPC_International_1985-08 (https://archive.org/details/06_Schneider_CPC_International_1985-08)
This article explaining what I wrote above reviewed a German joystick version lightpen and Light Painter software (which looks impressive compared to the Amstrad version)

QuoteHere is the wiki entry: https://www.cpcwiki.eu/index.php/Happy_Computer_Light_Pen
@GUNSHED had a look on archive.org but could not find it in the text
=firstTitle%3AH]https://archive.org/search?query=%22happy+computer%22&sort=title&and%5B%5D=firstTitle%3AH
 (https://archive.org/search?query="happy+computer"&sort=title&and[)
Lots of Happy Computer, but assume we want the 'Schneider Sonderheft versions'. They have 2,4,6,7,8 there. Assuming its one of the missing ones which has the article
Title: Re: How to make an optic pen?
Post by: GUNHED on 17:59, 27 December 23
One simple solution...
Title: Re: How to make an optic pen?
Post by: darkhalf on 08:58, 28 December 23
Thanks. Looks similar to the other magazine diagram posted but different resistor values, and slight change in arrangement


From LHS to RHS I think we have:
blue/grey/brown 680 ohm
blue/grey/brown 680 ohm
grey/red/orange? 82K ohm?
orange/grey/brown? 18K ohm?

Please let me know if I have the colours wrong. Assuming cap is 0.1uf

If the transistor is a BC547 (similar to the other circuit) then the order is 1 = collector, 2 = base, 3 = emitter (which goes to negative)  and that makes the brown wire negative, and blue positive (once again correct me if wrong)

The phototransistor however in this circuit connects between directly to the 5V rail, and then to the 680 ohm to negative rail. Still has a cap between the transistor base and the phototransistor 
Title: Re: How to make an optic pen?
Post by: darkhalf on 09:00, 28 December 23
Attachment with joined photo (inverted reverse side for clarity). Will use a veroboard and MX4 connector to build this one up and post results
Title: Re: How to make an optic pen?
Post by: darkhalf on 11:28, 28 December 23
I've attached the original magazine schematics with values attached. Whilst drawing this up I found an error (doesn't match their track layout). The linkage from 680k to both collector and base is incorrect. I've removed this

Also hand drawn are the Happy Computer (GUNSHED - top) from the above board and the Amstrad Mag (below).

Assume 1nf capacitor (0.1uf) after rereading and SP201 as a suitable substitute phototransistor since BPW42 are not available

From what I'm understanding so far, the Happy Computer may be using a positive bias instead of negative bias with using the phototransistor?

[Update - 1nF on Amstrad mag should be on lightpen side. Cannot update attachment]
Title: Re: How to make an optic pen?
Post by: darkhalf on 12:06, 28 December 23
Updated (rough) schematics for DK'Tronics and Amstrad Magazine attached. 

Note that the schematic is almost identical between both, apart from some minor resistor value updates (620ohm vs 670ohm pull up on LPEN line, and 22K vs 15K pull down on photo transistor line)

Other differences. DK'Tronics had a 2.2 ohm resistor to the phototransistor and Amstrad mag instead has 1nf cap 

Going to try this with a breadboard first due to the variances, and I only have the LP-1 phototransistor here to experiment with currently
Title: Re: How to make an optic pen?
Post by: darkhalf on 14:42, 28 December 23
Slight adjustment on above Amstrad Mag circuit (2.2K resistor should be on lightpen side of capacitor). This effectively puts 5V at the light transistor via this resistor.

Built the circuit on breadboard and only applied external 5V power and measured the LPEN output. Conclusion - photo transistor from the LP-1 didn't like this circuit. Need to find/try the proper photo transistor (SP201)

Only positive note so far is DK'Tronics ROM boots and runs fine in external ROM slot 1. Just needs a working light pen circuit to use it
Title: Re: How to make an optic pen?
Post by: Bryce on 15:41, 28 December 23
Quote from: darkhalf on 12:20, 27 December 23
QuoteAlso the lightpen on the 50pin port has the fantastic benefit of it getting directly attached to the CRTC and you can then just read the CRTC lightpen register to understand where it actually has hit the screen. So I think it cannot get better than that
CRTC only can measure at character positions. This is the DK'Tronics and other implementations. Poll the CRTC to get the position and convert to X,Y

How do you mean "at character positions"? If that was the case, then no pixel level graphics would be possible (or maybe I've mis-understood what you mean).
The DK'Tronix lightpen is triggering on the light of the CRT ray scanning the screen and is exact to the pixel.

Bryce.
Title: Re: How to make an optic pen?
Post by: darkhalf on 00:45, 29 December 23
QuoteHow do you mean "at character positions"?
Just from what I read here:
https://archive.org/details/06_Schneider_CPC_International_1985-08 (https://archive.org/details/06_Schneider_CPC_International_1985-08)

Translated from Page 11:
QuoteThe Schneider CPC owns the expansion Port at pin 47 Light pen connection. A precise processing of the values received there takes place in the kernel ROM. Because of the peculiarity of the CPC video controller But it is only possible to have one to achieve character-by-character resolution.

This is enough for positioning and for Menu controls completely off. Want However, you can get high-resolution  graphics create with the lightpen, that's how it comes you can only move on with a trick. The Lightpen connects to the joystick port or any data line of the bus system connected and then the switching states are queried.

For this purpose you color it Screen black if possible and creates a bright Sign. Now the light pen hits this sign. a signal is present and the corresponding address of the  Bus line is switched to the logical one Potential set to  high". This is how you leave it the screen character in a radius of 1 character (character). rotate and move on its own axis the lightpen in the desired one Direction. Every time. if the rotating Sign a signal to the Lightpen sends. will be the current one Position raised to base position and the process repeats itself. This The method has the disadvantage that it... works very slowly, but is through an average calculation the drawing in high-resolution graphics possible.

As in the basics of Lightpen mentioned. you have it at the CPC two possibilities. a light pen to operate. Both have their flaws, although the more serious one clearly when connecting to the expansion Port is located. For this reason the manufacturers of the LightpenPainter probably also for the connection decided the joystick port. this means Lwas a somewhat unusual one and slow processing, however through the advantage of drawing in HRG can as well as an excellent one Software, is balanced. The program is mainly for graphical purposes Thought to work, but can also as a menu control for your own User programs are used.

A demo disk shows how something built into basic programs becomes. In addition to the main program and there is another one in the demo RSX extension named .,Picture" on the disc containing the Lightpen creates images conveniently in your own programs are recorded can do that. The real highlight, however, is the May program, that all contains functions. with that too inexperienced draftsman is able to create his ownto create images
Title: Re: How to make an optic pen?
Post by: darkhalf on 01:19, 29 December 23
QuoteThe DK'Tronix lightpen is triggering on the light of the CRT ray scanning the screen and is exact to the pixel.
Not from what I'm reading: MC6845.PDF Data Sheet

QuoteLPEN High (R16) and Low (R17)
These registers together comprise a 14-bit register whose contents is the light pen strobe position, in terms of the video display address at which the strobe occurred. When the lPEN Input changes from low to high, then, on the next negative-going edge of CClK, the contents of the internal scan counter is stored in registers R16 and R17

R16 = Light Pen Reg (H) (5..0)
R17 = Light Pen Reg (L) (7..0)
(Also noted that R14/R15 are a 14-bit cursor register with same calculations)

Light pen register R16/R17 = Refresh memory address value. DK'Tronics reads these by setting register address in 1C00 and reading value from 1F00

Refer Section 13 DK'Tronics_Graphics_Lightpen_(ROM_Version)_Manual.pdf

Note: X ranges 0-39 and Y ranges 0-24 irrespective of mode

Calculations:
XYPos = R16 << 8 | R17 - 12292
YPos = XYPos / 40
XPos = XYPos - YPos * 40
Title: Re: How to make an optic pen?
Post by: darkhalf on 02:20, 29 December 23
Trying to find that Lightpen Painter software (no luck) but did find a youtube video for DK'Tronics light pen
https://www.youtube.com/watch?v=QG-WcZnpZuE (https://www.youtube.com/watch?v=QG-WcZnpZuE)

Around 5:40 he is commenting on the lack of accuracy (cursor is shaking) and you can see the draw results at 7:30 (pictured below). Perhaps DK'Tronics software attempts using some interpolation between squares?

You will note he is also drawing on a white background, to get the lightpen to respond. With DK'Tronics pen, fortunately you can continuously get updates on its (cursor based) position

Whilst the Amstrad (joystick port version) lets you position on a black screen, but then needs SPACEBAR press to trigger the read. Upon press, software knows only the pixel accurate Y position, and then draws a white block about 20 pixels high across until the light pen detects it. It uses this detection for pixel accurate X position. The process takes about 2-4 seconds per point (!)

To get something working better than either method I was thinking you could potentially combine them. 

1. Use the CRTC LPEN input to determine the immediate X,Y character position of the pen (against white background)

2. Push button to the pen (connected to joystick port Fire) to trigger light pen operation

3. Upon trigger, read the Y pixel position (via the DOWN arrow joystick read)

4. Start drawing vertical lines 8 pixels high at the X,Y character position to get the X pixel position

Obviously this would need updated drawing software to use a more accurate version of this pen, and some experimenting on correct resistor values for the photo transistor to both joystick and LPEN inputs
Title: Re: How to make an optic pen?
Post by: darkhalf on 03:45, 29 December 23
Doing some more reading of the LP-1 manual for the Amsoft package and you need to keep space held down for free draw to work properly

1. Whites the screen for pen detect
2. Upon detect will draw a horizontal bar
3. Then draws a pixel based on current X,Y pixel position (in black) 
4. Draws a box behind the pixel which follows the pen (whilst in the box) and draws pixels 

If the pen moves outside the box, you need to repeat the process. Movement is a bit jaggered, but the output at pixel resolution detection better than the character based from DK'Tronics demonstration
Title: Re: How to make an optic pen?
Post by: darkhalf on 09:48, 29 December 23
Attached are the BASIC and some slightly commented disassembly files for the Amstrad/Trojan software via joystick port. 

The 'draw' versions are cut down versions of the originals with more commenting

Some documentation on using the lightpen for menu cursor scanning, but if you are wanting to use the graphics parts then this is undocumented. Done some minor reverse engineering on this (haven't looked at Z80 in years) against the AY-3-8912, UpD-8255, CPC Firmware guide and Ins/outs of the Amstrad CPC464 book to get a start on this

Using the CRTC read method for the DK'Tronics unit is much easier than this
Title: Re: How to make an optic pen?
Post by: andycadley on 12:11, 29 December 23
You can see why these never really caught on, they're way too janky and the resolution is far too limited for drawing without hacky work arounds.

Character based accuracy was "good enough" for light gun style shooting games but that's not much cop if you then have to put the light pen right up against the screen...
Title: Re: How to make an optic pen?
Post by: darkhalf on 13:47, 29 December 23
Agreed. Reading the comments on YouTube etc confirms they were not as anticipated.  I remember the C64 Koala pad worked ok but limited uses on that computer. Would like to get this better but waiting on parts now and holidays almost over here
Title: Re: How to make an optic pen?
Post by: GUNHED on 18:20, 29 December 23
Darkhalf is right. On hardware level there is no pixel-precision. Only CRTC positions.

On a software level on the other hand some kind of sophisticated coding can simulate it. (Using the noise).
Title: Re: How to make an optic pen?
Post by: Brocky on 09:07, 02 January 24
nice investigation there @darkhalf i think im gonna leave this project on the back burner, it doesnt see to work as well as we all expected....

...maybe lightgun would be a better project..
Title: Re: How to make an optic pen?
Post by: darkhalf on 07:46, 03 January 24
@Brocky I'm still going to give it a shot when the parts arrive, but yeah the output doesn't look that promising for the DK'Tronics version. There are some other types of software such as Electric Studio etc which may work better, but overall having character resolution input isn't that great

If there was a way to use the CTRC and joy input together, and output that as a more accurate 'CRTC like' output then this would be a better solution and still would work with existing CPC software. So I'm not going to shelve it just yet but could be a bit of effort
Title: Re: How to make an optic pen?
Post by: andycadley on 08:48, 03 January 24
Quote from: darkhalf on 07:46, 03 January 24If there was a way to use the CTRC and joy input together, and output that as a more accurate 'CRTC like' output then this would be a better solution and still would work with existing CPC software. So I'm not going to shelve it just yet but could be a bit of effort

Theoretically, I don't see why not. Use the CRTC method to get the character position, the flash a bunch of white rectangles inside that character to locate the actual pixel position. Having two wires coming from the pen (one to the expansion port, the other the joystick port) would make it even more cumbersome to use however. Although I guess there is no reason you couldn't do something similar via another IO port.
Title: Re: How to make an optic pen?
Post by: darkhalf on 11:27, 03 January 24

QuoteHaving two wires coming from the pen (one to the expansion port, the other the joystick port) would make it even more cumbersome to use however.
Agreed. However compared to the amount of other peripherals coming out of my CPC, it probably won't matter!

Quote Although I guess there is no reason you couldn't do something similar via another IO port.
Stopped digging too far into the Dart circuitry in the first posts, but do wonder if they did something like that. There is a fair bit of 74 series logic going on there. Software link here. Some article in French too

https://www.cpc-power.com/index.php?page=detail&num=5853 (https://www.cpc-power.com/index.php?page=detail&num=5853)
Powered by SMFPacks Menu Editor Mod