Flashing a particular coordinate like a cursor in lo-res mode

6 posts / 0 new
Last post
Offline
Last seen: 8 months 2 hours ago
Joined: Jan 1 2021 - 09:56
Posts: 26
Flashing a particular coordinate like a cursor in lo-res mode

I'm in the middle of working on some personal coding projects in BASIC, and I'm curious as to how one might implement this:

I've written a simple drawing program that allows you to move around the screen and draw blocks on the screen in lo-res mode, with a portion of the text window reserved for displaying your X,Y position. The problem is that if you're not drawing anything, it's a little hard to know exactly where the cursor is, even with the coordinates displayed. 

Essentially, what I want to do is to take the current X,Y position on the screen and numerically invert (so color 0 becomes color 15, color 1 becomes color 14, etc) whatever color is there (and ideally, "blink" it, flipping beween normal and inverted) so you can see where you're drawing.

I know that the screen memory layout is from 1024-2047, split into three 128-byte segments, with the last 8 bytes of each segment reserved for the "screen holes". However, because each screen memory byte represents two possible vertically-adjacent positions on the screen (low-order bytes being the top, high-order being the bottom) I'm a little lost as to how I would come up with something that's relatively straightforward to not only select the correct address to poke changes into, but also make sure that what's poked in modifies only the correct part of the memory location -- either the low-order or high-order bits. 

I've seen the thread about help with PEEKing the text screen, and that gives me a good idea of where to start (especially with an assembly language program that allows it to do the math to figure out the correct memory address), but I'm not fully certain how I would translate that to essentially a bitwise NOT, but only on the correct 4 bits instead of 8. 

Any help here would be appreciated -- something that could send me in the right direction would be awesome!

Offline
Last seen: 4 days 28 min ago
Joined: Jun 25 2020 - 17:00
Posts: 223
Which BASIC? INT or FP

May we assume Floating Point Basic?

Offline
Last seen: 8 months 2 hours ago
Joined: Jan 1 2021 - 09:56
Posts: 26
Yes - assume Applesoft BASIC.

Yes - assume Applesoft BASIC.

Offline
Last seen: 4 days 28 min ago
Joined: Jun 25 2020 - 17:00
Posts: 223
Which BASIC? INT or FP

May we assume Floating Point Basic?

 

Let's do.  The program flow whether in FP or machine code would need to be a program loop something like this after GR mode is declared.  For simplicity assume a XY input device like a joystick using the paddle inputs.  Assume cursor color is either WHITE or BLACK.

 

1.Set Draw Color DC

2.  Read the XY values of the paddle (at any given time they will "read" between 0 and 255) and store them in variables PX, PY

3.  Is "Draw" button depressed?  If YES set D=1, If NO set D=0

4.  Scale paddle values to the LORES screen coordinates and store them in SX, SY

5.  Read the LORES screen  pixels coordinate and color at SX, SY, SC and store them in RX, RY, RC  (if pixel color is BLACK then Cursor Color (CC) is WHITE otherwise Cursor Color is WHITE)

5.  If D=1 then Cursor Color = Draw Color (DC) ELSE DC=CC

6.  PLOT the Cursor Color at SX, SY

7.  If D=1 GOTO 8 ELSE PLOT the pixel color SC at SX, SY

8.  Check to see if Draw button is still pressed, if Yes DC=Draw Color ELSE DC=CC

9.  Check for ESC keypress, if YES, then GOTO EXIT, if NO then repeat 1 thru 6.

 

That is the general idea at least.   BTW: I haven't tried this in actual code.

 

Have fun.

InexorableTash's picture
Offline
Last seen: 1 month 1 week ago
Joined: Jan 27 2023 - 13:44
Posts: 10
Use SCRN()

Since you write that you've already written the drawing program from Applesoft, I assume you're using PLOT?

Have you considered using the SCRN() function to read the pixel value? e.g. this would flash the pixel at X,Y:

CL = SCRN(X,Y) : COLOR= 15 - CL : PLOT X,Y : COLOR= CL : PLOT X,Y

 

Offline
Last seen: 8 months 2 hours ago
Joined: Jan 1 2021 - 09:56
Posts: 26
So that code would do it --

So that code would do it -- now, I'm thinking my way through how to leave the existing data unchanged when you move the cursor so that if you move while the cursor is "on," you don't inadvertently change the color of the existing pixel.

 

Log in or register to post comments