{"id":25957225,"date":"2024-03-22T17:18:19","date_gmt":"2024-03-22T16:18:19","guid":{"rendered":"https:\/\/msxitalia.org\/?p=25957225"},"modified":"2024-03-22T17:18:22","modified_gmt":"2024-03-22T16:18:22","slug":"lezione-26-interval-on-rnd-ed-altri","status":"publish","type":"post","link":"https:\/\/msxitalia.org\/en\/lezione-26-interval-on-rnd-ed-altri\/","title":{"rendered":"LESSON 26 \u2013 INTERVAL ON, RND AND OTHERS"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Good morning everyone,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this episode I will talk about an important interrupt, especially for games, when we want to make an enemy suddenly appear or a useful object, but also to create a stopwatch or a clock and many other things. The COMMAND uses the time that is automatically updated by our MSX which occurs every fiftieth of a second. But let&#039;s go in order. Always at the beginning of the program we insert the command line: ON INTERVAL = Time GOSUB Line number. It happens that, when we activate this command, in our MSX it begins to count the TIME (always in fiftieths of a second), when this reaches the figure set after the equal, it will jump to the subroutine after the GOSUB, leaving what it is doing. After performing the routine, he will return to where he left off. The command will come into operation after activation with INTERVAL ON. With INTERVAL OFF it will be deactivated and with INTERVAL STOP it will be suspended, to restart it we will always give INTERVAL ON. Below is a small demonstration of a stopwatch.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">10 KEY OFF: DEF INT AZ: SCREEN 0: WIDTH 40: ON INTERVAL = 50 GOSUB 100 20 S=0: M=0: INTERVAL ON 30 LOCATE 1,11: PRINT \u201cMINUTES:\u201d;M; \u201cSECONDS:\u201d;S 40 LOCATE 1,20:PRINT \u201cPress space to stop the timer\u201d 50 IF INKEY$&lt;&gt;CHR$(32) THEN 50 60 INTERVAL OFF: END 100 S=S+1:IF S=60 THEN M =M+1:S=0 110 LOCATE 1,11: PRINT \u201cMINUTES:\u201d;M; \u201cSECONDS:\u201d;S: RETURN  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The RND Function creates a random number between zero and one. It can be inserted into a variable: A=RND(1), or printed on the fly with PRINT: PRINT RND(1). The number inside the brackets is fictitious. If we put a positive number, it will always repeat the same sequence of numbers, but if we want this not to happen, we can use the TIME function in a negative way: A=RND (-TIME). TIME is a function used in MSX-DOS to set the time. In Basic we can say that it is a reserved variable, which counts the time in fiftieths of a second from the moment we turn on our MSX. It can also be reset: TIME=0. It is very convenient for seeing the execution times of a part of the program. To give an example, if we want to see the time taken for a subroutine we put at the beginning, TIME=0 and at the end we see the result, adding PRINT TIME. Let&#039;s remember that its result will always be in fiftieths of a second.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, I will mention all the remaining commands, little used or used by expert programmers, but useful to know what they are for.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">DSKF returns the number of free sectors on a disk. The correct syntax is: DSKF(Drive Number). Drive Number can be 0 for the current one, 1 for DRIVE A and 2 for DRIVE B          <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> MOTOR ON\/OFF, starts and stops the cassette recorder motor. Command rarely used, especially because in most programs, MSX does it automatically.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">TRON\/TROFF is useful for doing line-by-line checks in our programs, in fact it enables the display of line numbers while a program is running. Just activate it before giving the RUN by typing TRON. To deactivate the function, TROFF<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PAD(n), Reads data from the graphics tablet. Where n can have a value from 0 to 7. From 0 to 3 are the data for port 1. 0 activates port 1, 1 reads the X coordinate, 2 the Y coordinate and 3 the state of the button, if the button is pressed its value will be -1. Same thing for the remaining 4,5,6,7. 4 reads 2, 5 reads X, 6 reads Y and 7 reads the button state.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PDL(n) controls the paddle, where n is the port number like the joystick. The function can take on a value from 0 to 255 with respect to the eight joystick movements. To control the button we can use the STRIG function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">CALL calls a machine language routine, either created by the user or resident in ROM: CALL FORMAT.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">OUT Address, Data. Sends a byte to the specified address. Data ranges from 0 to 255.       <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">INP(Address), Returns a byte from the specified address.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">WAIT waits for data from an I\/O port to satisfy certain conditions: WAIT Port, AND Expression, XOR Expression.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">VARPTR(Variable), Returns the starting address where a value assigned to the specified variable is stored.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">POKE Address, given, Changes a RAM address. Data ranges from 0 to 255<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PEEK(Address), reads data from a RAM address.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">VDP(register) or VDP(register)=value. Reads or modifies VRAM VDP registers. The registers go from 0 to 8, the last one i.e. eight can only be read.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">BASE(n ) or BASE(n)=VramAddress, Reads or modifies the first address of the VDP tables. n is between 0 and 19.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">DEFUSR calls a machine language program. the correct syntax is DEFUSR(n)=start address. n goes from 0 to 9, i.e. up to 10 programs can be opened. Start address is the starting point where the routine was stored.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">USR(n). is used to start a program in LM called with DEFUSR. The correct syntax is: Variable=USR n (number). Both variable and number are dummy arguments, we can put whatever we want. Instead n is the number with which the program was opened in LM Example: DEFUSR0=&amp;H41: A=USR0(1).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">VPOKE modifies a data in the Vram, VPOKE Address, data. Address goes from 0 to 16383 (the 16 Kb of video memory), data goes from 0 to 255.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">VPEEK reads the set address data from VRAM: VPEEK(Address)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This was the last feature. We have reached the end. I apologize if some topics were not understandable or I was not good at explaining them, but I tried to do it in the simplest way possible, avoiding words or synonyms used by &quot;experts&quot;, given that beginners would have made the explanation difficult. even less understandable. I thank all the people who have followed and I hope this has been helpful in starting to do something, even a little, the important thing is to start. I will always be at your disposal for any doubts, clarifications and information. You can write on the various sites or forums of the MSX Italia Association. Unfortunately I don&#039;t have much time to follow everything, but if I&#039;m not the one to answer you, other more knowledgeable members will be happy to help you.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Again, heartfelt thanks to everyone.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ps: Given the requests of some of you, I will do an extra lesson, I will explain how to &quot;build&quot; the Tiles and set the collisions with them, which will help a lot for those who want to create simple Platforms.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>","protected":false},"excerpt":{"rendered":"<p>Buongiorno a tutti, In questa puntata parler\u00f2 di un interrupt importante, specialmente per i giochi, quando vogliamo far apparire un nemico all&#8217;improvviso o un oggetto utile, ma anche per creare un cronometro o un orologio e tante altre cose. Il COMANDO sfrutta il time che viene aggiornato automaticamente dal nostro MSX che avviene ogni cinquantesimo [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":6311,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[14],"tags":[],"dipi_cpt_category":[],"class_list":["post-25957225","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-msx-basic"],"_links":{"self":[{"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/posts\/25957225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/comments?post=25957225"}],"version-history":[{"count":10,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/posts\/25957225\/revisions"}],"predecessor-version":[{"id":25957240,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/posts\/25957225\/revisions\/25957240"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/media\/6311"}],"wp:attachment":[{"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/media?parent=25957225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/categories?post=25957225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/tags?post=25957225"},{"taxonomy":"dipi_cpt_category","embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/dipi_cpt_category?post=25957225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}