WHITE LIGHTNING - EXAMPLES SOME SIMPLE PROGRAMMING EXAMPLES Example 1 To scroll a window at row 8, column 9, 5 characters high by 10 characters long, 1 pixel to the left with wrap: : DEM1 5 HGT ! 10 LEN ! 8 ROW ! 9 COL ! WRL1V ; To put some data on the screen: VLIST To scroll the window 100 times: : DEM2 100 0 DO DEM1 LOOP ; DEM2 To execute DEM1 in background: ' DEM1 INT-ON To halt the background execution of DEM1: INT-OFF Example 2 To scroll a window at column 12, row 3, 10 characters high and 5 characters wide, downward by 3 pixels with wrap: : DEM3 10 HGT ! 5 LEN ! -3 NPX ! 2 ROW ! 12 COL ! WCRV ; to define the word, then: DEM3 to execute it. To run DEM3 in background: ' DEM3 INT-ON To halt the background execution: INT-OFF Example 3 To invert a window at column 10, row 5, 4 characters high and 4 characters wide: : DEM4 4 HGT ! 4 LEN ! 5 ROW ! 10 COL ! INVV ; and then: DEM4 to execute. Example 4 It is not always necessary to use colon definitions to achieve a particular result. To PUT sprite 34 (if you've got the demo sprites loaded or have already defined your own sprite 34) at row 5, column 6, and replace any data currently at that position: 34 SPN ! 5 ROW ! 6 COL ! PUTBLS Example 5 Often it is useful to define a word which carries out an operation that is used frequently and which saves typing; for instance: : DEM5 COL ! ROW ! SPN ! PUTBLS ; If we wanted to carry out the simple PUT command in example 4, all we'd need to type would be: 34 5 6 DEM5 Example 6 To scroll sprite 29 in memory by 1 pixel to the right with wrap and PUT it on the screen at row 10, column 11, use: : DEM6 29 SPN ! 10 ROW ! 11 COL ! WRR1M PUTBLS ; To run DEM6 in background use: ' DEM6 INT-ON Example 7 To fill a screen window, at column 17, row 5, 5 characters long and 10 characters high, with the attributes - 6 INK, 2 PAPER, 1 FLASH - use the following: : DEM7 1 FLASH 6 INK 2 PAPER 10 HGT ! 5 LEN ! 13 ROW ! 17 COL ! SETAV 0 FLASH 7 INK 1 PAPER ; Example 8 To change the green face of sprite 28 into a red one use: : DEM8 28 SPN ! 2 INK ! 1 BRIGHT 0 PAPER SETAM PUTBLS ; Example 9 To pick a random number between 0 and 100 use: : DEM9 100 RND . ; Example 10 To pick a random INK colour and change sprite 34's INK colour to this colour, and then put it at column 10, row 10, use: : DEM10 7 RND INK 34 SPN ! SETAM 10 ROW ! 10 COL ! PUTBLS ; To run DEM10 in background use: ' DEM10 INT-ON and to halt DEM10 use: INT-OFF Example 11 To place sprite 24 into the screen of sprite 13 use: : DEM11 24 SP1 ! 13 SP2 ! 7 SCOL ! 6 SROW ! GWBLM 10 ROW ! 10 COL ! ATTON PUTBLS ; Example 12 To XOR sprite 43, the explosion, with sprite 27, the 270 degree rotated Invader, in memory, use: : DEM12 43 SP1 ! 27 SP2 ! COPXRM 10 ROW ! 10 COL ! 27 SPN ! ATTON PUTBLS ; Example 13 To invert sprite 7, the spider, in memory, use: : DEM13 7 SPN ! INVM 10 ROW ! 10 COL ! PUTBLS ; Example 14 To enlarge sprite 24 into sprite 45 using the DSPM command, use: : DEM14 45 SP1 ! 24 SP2 ! DSPM 45 SPN ! 10 COL ! 10 ROW ! PUTBLS ; Example 15 To search through sprite space, locate any existing sprites, print out the start of data, length and height, use: : DEM15 255 1 DO I SPN ! TEST 1 = IF I. SPACE DPTR @ U. SPACE LEN ? SPACE HGT ? SPACE CR THEN LOOP ; Example 16 To scroll a landscape sprite numbered 128, 2 characters high and 64 characters wide, left by 1 pixel under interrupt, use the following: SCR # 6 0 0 VARIABLE CL 8 VARIABLE PH : OPEN EXX 0 COL ! 12 ROW ! 2 HGT ! 1 0 SROW ! 0 SCOL ! 128 SPN ! 0 PAPER 6 INK 32 LEN ! CLSV O INK 2 1 LEN ! CLSV 32 LEN ! PWBLS EXX ; 3 : NXB CL @ 1+ DUP 64 = IF DROP 0 ENDIF DUP CL ! 31 + 64 MOD SCOL 4 ! 1 LEN ! PWBLS 32 LEN ! ; 5 : SL WRL1V PH @ 1- DUP 0= IF NXB DROP 8 ENDIF PH ! ; 6 : GO 6 INK 0 PAPER 0 BORDER 1 BRIGHT CLS 14 ROW ! 1 COL ! 7 6 PAPER 31 LEN ! 4 HGT ! SETAV OPEN 6 INK ' SL INT-ON ; To speed this up to faster 4 or 8 pixel scrolls change lines 0 and 5 to read: 0 0 VARIABLE CL 2 VARIABLE PH : OPEN EXX 0 COL ! 12 ROW ! 2 HGT ! 5 : SL WRL4V PH @ 1- DUP 0= IF NXB DROP 2 ENDIF PH ! ; 0 0 VARIABLE CL 1 VARIABLE PH : OPEN EXX 0 COL ! 12 ROW ! 2 HGT ! 5 : SL WRL8V PH @ 1- DUP 0= IF NXB DROP 1 ENDIF PH ! ; Type 6 LOAD to compile and GO to run. -- end of Examples