Sketch-PadDles

Copyright © 2017 by Víctor Parada

Sketch-PadDles

This is a little game for the 2017 NOMAM's BASIC 10-liners Contest. This program fits in the PUR-80 category, and it was written using TurboBASIC XL 1.5 for the 8-bits ATARI XL/XE. Development started on 2017-03-20, and it took 1+1 days. The final version's date is 2017-03-29.

UPDATE: It obtained the 18th place of 26 entries in the category.


Description

Use your paddles to draw in this Etch-a-Sketch simulator. Save your art and restore it later.


Instructions

SKETCH start When the game starts, a stright line may appear from one edge to the location where your paddles point to. Move the paddles to learn how to use them, then select a starting location in the screen where your art will begin.
SKETCH clear Press START key or any of the paddles' buttons to clean the screen.
SKETCH drawing Draw whatever you want. Remember that you are using a continuous line. No skips are available.
SKETCH-save When finished, press any number to save your art into the disk inserted in drive 1. Be sure that it is not write-protected and it has enought space (8K per file number). Warning: If you save a 2nd piece of art using a number already used in that disk, the old image will be overwritten (and lost).
SKETCH-load To load a previously saved art, press SHIFT and the number you used for that image in the disk.
SKETCH restart To start a new piece of art, press START or any of the paddles buttons again.

Development of the game

When I was a kid, I played with a toy called Etch-a-Sketch, and it came into my mind when I was thinking for a paddle game that could be programmed for the BASIC tenlines. It could be fun to use 2 paddles at the same time!!!

The first prototype was easy to program: just a single loop checking for changes in the PADDLE(0) and/or PADDLE(1) registers and perform a DRAWTO to that coordinates. As I was using graphics mode 8 (without text box), I got a monochrome screen of 320x192 pixels. Light-gray background, black lines and red margin, just like the original toy. Good!!! No, bad... because paddles use a range from 0 to 228, and that is less than the width of the screen, so it is impossible to stay over some columns. And that was not all: artifacting... a black&white NTSC screen full of vertical lines displays green and pink areas. Ugly!

SKETCH with artifacts

Artifacting in graphics mode 8 over NTSC screen

To bypass both problems, I changed to graphics mode 15, and the screen become 160x192 pixels, both values in the paddle's range, and only a simple range scale is required on each axis to map all the pixels of the screen. But now, the background got the border color (red), so I had to change the color registers and fill the background with a color register different from 0, and I choose COLOR 3. To draw, COLOR 2 is used instead of COLOR 1.

SKETCH with paddles

Using SKETCH with paddles in real Atari

The code was really short, and as I lost some really nice drawings during my tests, I wanted to add the ability to save the art and to load it again later. I kept it simple and, without an interface, it is posible to save (and load) up to 10 images in a diskette by a single key press. Files are named "SKETCHn.SKP" as it could be verified using a DOS or typing DIR command in TurboBASIC XL. "n" is replaced by the number in the key used to save the file, from 0 to 9.

One thing I wanted to add was the graphical representation of the toy's white knobs in the bottom corners of the screen using P/M, but I've omitted them because they could be placed outside the TV screen area, I think that the cleaning effect is enough for this simple simulator, and you have real knobs in your hands. And it fits in the PUR-80 category of the contest!


Download and try

Get the SKETCH.ATR file and set it as drive 1 in a real Atari (or emulator). Turn on the computer and the game should start after loading. A set of paddles in port 1 is required. I suggest using mounting putty to fix the paddles on a smooth surface.

Notes for Altirra users:

If you want to try it in Altirra emulator, you must create a special input mapping for Paddle B with the following parameters:

This mapping is very different to the mapping for Paddle A, and if you set up Paddle B like Paddle A currently is, your vertical moves will be upside down. To enable both paddle mappings at the same time, check both of them in the Input Mappings window, not by selecting them from Port 1 menu option.

Another issue is related to save/load keys: To save files, you must press a number key, but to load, SHIFT key won't work as expected, because Altirra uses a keyboard mapping to assign the internal key-codes to corresponding labeled PC keys, and not all the SHIFTed numbers in the Atari have the same symbol as the same SHIFTed numbers in the PC keyboard, because the layouts are different. Instead of changing the layout setup in Altirra, a simple workaround is to press SHIFT+CONTROL and the number of the file to load, except for "0", where a only CONTROL is required.

Finally, do not press any of the mouse buttons while you are drawing, because your art would be cleared!!! Remember that this game is always in drawing mode.


The code

The abbreviated BASIC code is the following:

The full and expanded BASIC listing is:

graphics 31
Sets graphics mode 15+16: 160x192 pixels, no text box, and 4 colors including the background are available, but only 2 colors and no background will be used.
dpoke 709,$0C00
Sets the palete only for the 2 used colors.
poke 712,$26+$10*(peek($D014)&$E>0)
Sets the palete for the background as red. The background will only be seen in the borders (margin). The PEEK is used to recognize if it is a PAL or NTSC Atari, as red have different a HUE value for each TV standard.
dim f$(15)
f$="D:SKETCH0.SKP"
Sets the name of the file to save and restore art. The number will be replaced with the corresponding key when pressed.
p=dpeek(560)
Start of the display list.
s=dpeek(88)
Start of the screen memory area.
n=40*192
Total number of bytes in the screen.
poke s,$FF
move s,s+1,n
Initialices the screen area, filling all of it with color 3.
color 2
Sets color 2 for the drawings.
do
Infinite loop:
  x=trunc((228-paddle(0))*160/229+0.5)
  y=trunc((paddle(1))*192/229+0.5)
Detect current coordinates of the pointer based on paddle positions. Paddle values are scaled to the screen size and direction.
  if a<>x or b<>y
Detect if at least one of the axis changed
    drawto x,y
Draws a line from the previous location to the new one.
    sound 0,(a>x)*3+(b>y)*2,8,3
Adds some FX...
    a=x
    b=y
Saves the new coordinates.
    poke 77,0
Turns off ATRACT mode every time a line is drawn.
  else
    sound
Shuts up if no paddle was moved.
  endif
  if stick(0)<15 or peek(53279)=6
Detects if one of the paddles' buttons or the START key was pressed.
    for i=0 to 6
      poke 709,i*2
      for j=0 to 13
        k=peek(adr("{data}")+j)
        pause 0
        poke p,k
        sound 0,k/16,8,8
      next j
    next i
Shake effect: this changes the top of the display list removing one scan line for some times to move the display up and then restoring them again to movi it down, with a proper sound and slowly fading out the drawing at the same time. Binary data contains the sequence of ANTIC blank instructions to create the FX.
    poke s,$FF
    move s,s+1,n
Cleans the screen...
    poke 709,0
... and restores the color for the new drawing.
  endif
  if peek(764)<255
Detects if any key was pressed.
    k=peek(764)
Gets the internal code of the key, not the ATASCII character number.
    t=1
Flag to check for I/O errors.
    j=1
Flag to set up R/W operation. Initialiced as "write".
    if k>64
Checks if SHIFT and/or CONTROL keys were also pressed.
      k=k mod 64
Gets the internal code without SHIFT or CONTROL.
      j=0
SHIFT or CONTROL detected, then set up the I/O flag as "read".
      poke 764,k
Changes the internal code to represent the pure key.
    endif
    trap 9
If there is an error in the following instructions, skip to line "9" of the program.
    get i
Reads the pressed key.
    if i>47 and i<58
Accept only digits (ATASCII number between 48 for "0" and 57 for "9")
      f$(9,9)=chr$(i)
Updates the file name with the selected number.
      open #1,4+4*j,0,f$
Opens the file in "read" or "write" mode depending on the R/W flag.
      if j
        bput #1,s,n
Saves the screen data if "write" was selected.
      else
        bget #1,s,n
Loads data into screen if "read" was selected (using SHIFT and/or CONTROL)
      endif
    endif
  endif
  if t
    close #1
    t=0
  endif
The IF must be the first instruction in line "9". If the line number is not "9", the line number of the TRAP instruction must be changed accordingly.
loop
End of the main loop.

Return to my 10-liners page.

© 2017 by Víctor Parada - 2017-04-04 (updated: 2020-08-15)