i was making a tutorial on poking to the screen, and i found that my timing device was unreliable, as it often the time the programs took to run as 0. Can you guys help me? all the code is commented on. i'll outline the timing devices. here's my timer outside of the program.
t! = timer
'code... code...
print timer - t!
you'll find two of these, as one program uses pset, one uses poke.
'**********************begin code**************************
DEFINT A-Z '-this command makes all unsigned variables integers. it
'greatly speeds up this program.
DEF SEG = &HA000 '-this points the default segment to the graphics buffer.
'it is absolutely necessary for using poke, as pointing
'to the graphics buffer will make poke poke to the screen.
SCREEN 13 '-the screen resolution: 360x200x256: 360 pixels across,
'200 pixels up and down, and 256 colours available.
'**********************************************************
t! = TIMER '-this starts up our timer which will tell us how long
'it takes for the program to finish, clocking it.
'*****************************************************************
FOR y = 0 TO 199 '-these two loops will be the size of the pretty little
FOR x = 0 TO 319 'we're going to make. notice it is 0 to 199 and 0 to 319
'this is because we start counting at 0 not 1.
PSET (x, y), x MOD 256 '-we all know pset i hope. this will plot the coordinates
'then show the colour of our pixel.
NEXT 'moves on to the next x.
NEXT 'moves on to the next y.
'************************************************************
PRINT TIMER - t! 'after the program is finished, this will print how long
'in milliseconds it takes.
'******************************************************************
DO: LOOP UNTIL INKEY$ <> "" 'irrelevent for now, but it waits for a keypress.
CLS 'clears the screen. i heard line(0,0)-(319, 199), 0, bf
'is alot faster though.
ti! = TIMER '-this starts up our timer which will tell us how long
'it takes for the program to finish, clocking it.
FOR y = 0 TO 199 '-these two loops will be the size of the pretty little
'we're going to make. notice it is 0 to 199 and 0 to 319
'this is because we start counting at 0 not 1.
FOR x = 0 TO 319
'offset& = y * 320& + x will plot the point.surprisingly,
offset& = y * 320& + x
'this is faster than pset even though this is a double integer. lets break it down. 'ignore the & in the 320&.
'you know that the screen is 320 pixels wide. is it ringing 'a bell yet? y * 320& will determine how high
'to plot the pixel. here's how it 'works. poke does not work with two dimensions: it works with one. you
'know how to 'plot a point on a grid? (x, y) y is up and down, x is sideways. however, poke is 'different.
'it is plotted with just (offset&). the offset& is the address... the 'coordinates for the screen. the actual
'offset& of the entire screen is 319 * 199 ('remember 0!). if the offset is 319, it will put a pixel at the
'top right hand corner
'of the screen. if it is 320, you would think it has gone off the screen, right? (the 'screen is 0-319), but
'no! you see, poke is sort of like microsoft word. if your 'typing and you reach the end of the page, the
'text moves to the next row and 'continues from the beginning column. so 320 will be 1 row down and at the
'first 'column. so if y = 0 and x = 100, then the forumla is 0 * 320& + 100. 0 * 320 is 0, and 0 + 100 is '
100. so therefore it moves over 100 columns and puts a pixel there. if y = 3 and x = 100, then the formula
'is 3 * 320 + 100. 3 * 320 is 960. 960 + 100 is 1060. want to find the x and y? for formula is offset& = y *
'360 + x. the offset is 1060, so therefore 1060 = y * 360 + x. 1060/360= y + x. Now, we're going to have
'remainders. 360 goes into 1060 three times with a remainder of 100... y = 1060/360, rounded down. x is the
'remainder. so y = 3, (1060/360 rounded down) and x = 100 (the remainder.) hope this helps. email me and
'tell me what you think!
POKE offset&, x MOD 256 'i explained this above. offset& is the address. x mod 256 is merely the color to
'make the pixel. you don't need to understand this.
NEXT 'next x coordinate.
NEXT 'next y coordinate.
PRINT TIMER - ti! 'prints out how long this program takes.
DO: LOOP UNTIL INKEY$ <> "" 'irrelevant. waits for a keypress.
t! = timer
'code... code...
print timer - t!
you'll find two of these, as one program uses pset, one uses poke.
'**********************begin code**************************
DEFINT A-Z '-this command makes all unsigned variables integers. it
'greatly speeds up this program.
DEF SEG = &HA000 '-this points the default segment to the graphics buffer.
'it is absolutely necessary for using poke, as pointing
'to the graphics buffer will make poke poke to the screen.
SCREEN 13 '-the screen resolution: 360x200x256: 360 pixels across,
'200 pixels up and down, and 256 colours available.
'**********************************************************
t! = TIMER '-this starts up our timer which will tell us how long
'it takes for the program to finish, clocking it.
'*****************************************************************
FOR y = 0 TO 199 '-these two loops will be the size of the pretty little
FOR x = 0 TO 319 'we're going to make. notice it is 0 to 199 and 0 to 319
'this is because we start counting at 0 not 1.
PSET (x, y), x MOD 256 '-we all know pset i hope. this will plot the coordinates
'then show the colour of our pixel.
NEXT 'moves on to the next x.
NEXT 'moves on to the next y.
'************************************************************
PRINT TIMER - t! 'after the program is finished, this will print how long
'in milliseconds it takes.
'******************************************************************
DO: LOOP UNTIL INKEY$ <> "" 'irrelevent for now, but it waits for a keypress.
CLS 'clears the screen. i heard line(0,0)-(319, 199), 0, bf
'is alot faster though.
ti! = TIMER '-this starts up our timer which will tell us how long
'it takes for the program to finish, clocking it.
FOR y = 0 TO 199 '-these two loops will be the size of the pretty little
'we're going to make. notice it is 0 to 199 and 0 to 319
'this is because we start counting at 0 not 1.
FOR x = 0 TO 319
'offset& = y * 320& + x will plot the point.surprisingly,
offset& = y * 320& + x
'this is faster than pset even though this is a double integer. lets break it down. 'ignore the & in the 320&.
'you know that the screen is 320 pixels wide. is it ringing 'a bell yet? y * 320& will determine how high
'to plot the pixel. here's how it 'works. poke does not work with two dimensions: it works with one. you
'know how to 'plot a point on a grid? (x, y) y is up and down, x is sideways. however, poke is 'different.
'it is plotted with just (offset&). the offset& is the address... the 'coordinates for the screen. the actual
'offset& of the entire screen is 319 * 199 ('remember 0!). if the offset is 319, it will put a pixel at the
'top right hand corner
'of the screen. if it is 320, you would think it has gone off the screen, right? (the 'screen is 0-319), but
'no! you see, poke is sort of like microsoft word. if your 'typing and you reach the end of the page, the
'text moves to the next row and 'continues from the beginning column. so 320 will be 1 row down and at the
'first 'column. so if y = 0 and x = 100, then the forumla is 0 * 320& + 100. 0 * 320 is 0, and 0 + 100 is '
100. so therefore it moves over 100 columns and puts a pixel there. if y = 3 and x = 100, then the formula
'is 3 * 320 + 100. 3 * 320 is 960. 960 + 100 is 1060. want to find the x and y? for formula is offset& = y *
'360 + x. the offset is 1060, so therefore 1060 = y * 360 + x. 1060/360= y + x. Now, we're going to have
'remainders. 360 goes into 1060 three times with a remainder of 100... y = 1060/360, rounded down. x is the
'remainder. so y = 3, (1060/360 rounded down) and x = 100 (the remainder.) hope this helps. email me and
'tell me what you think!
POKE offset&, x MOD 256 'i explained this above. offset& is the address. x mod 256 is merely the color to
'make the pixel. you don't need to understand this.
NEXT 'next x coordinate.
NEXT 'next y coordinate.
PRINT TIMER - ti! 'prints out how long this program takes.
DO: LOOP UNTIL INKEY$ <> "" 'irrelevant. waits for a keypress.