TUTORIAL FOR OUT, PEEK, POKE

BY DANNY BEARDSLEY

'The Out commands (to modify I/O ports)
'the ports that I used are for changing the palette
'in order to change one color in the palette you first
'do an out command to &H3C8 and put the number of
'the color that you want to change
OUT &H3C8, 1 'to change color one
'then next three out commands are to &H3C9 to change the rgb values
OUT &H3C9, 35 'set red to 35 limit is 0 - 63
OUT &H3C9, 50 'set green to 50 limit is 0 - 63
OUT &H3C9, 15 'set blue to 15 limit is 0 - 63

'POKE and PEEK are memory write and read statments
'you can any address you want
'to access a certain address...(for instance the screen) you use
DEF SEG = &HA000 'the screen address (This is the address divided by 16...
'thats the way DEF SEG wants it)
'to write to the screen they are about 30 times faster than pset
'to use them to write to the screen you can do it 2 ways
 
(when using to write to screen you have to Screen 13 FIRST)
 
'----------WAY 1------------
SCREEN 13
DEF SEG = &HA000
'then to plot a pixel with coordinates of x and y and color c
POKE (y * 320 + x), c
'to read a pixel you
c = PEEK(y * 320 + x)
'then c will be the color of that pixel

'----------WAY 2------------ faster
SCREEN 13
'This way you can use integers because you DEF SEG to both the top of the screen and the
'middle so your y value is never bigger than 100 and 100*320 is not bigger than 32000 (integer limit)
'to plot a pixel in the upper half of the screen with coordinates of x and y and color c
DEF SEG = &HA000
POKE (y * 320 + x), c

'to plot a pixel in the lower half of the screen with coordinates of x and y and color c
DEF SEG = &HA7D0
POKE ((y - 100) * 320 + x), c
 
if you dont know what half of the screen your pixel is in do an if
IF y > 100 then
...
ELSE
...
END IF
'In every case use integers as much as you can!!! (10-20 times faster)