Programming

From Ninerpedia
Revision as of 18:23, 13 October 2014 by Stephen Shaw (talk | contribs) (Separate ExBas tips from ExBas extensions)
Jump to navigation Jump to search

See article Programming languages

Environments

See article Programming languages

This article contains some additional information relating to Extended BASIC .

BASIC and its extensions

The Myarc and the CorComp disk controllers added a number of additional support routines to the language.

Extended Basic Extensions

CALL LOAD requires Expansion Memory.

Useful CALL LOADs

Also see article on using Sound with CALL LOAD and Speech with CALL LOAD

Other systems are known for their PEEKs and POKEs, but neither TI BASIC nor Extended Basic offer such commands. Instead, we have CALL subprograms that do a similar job, CALL PEEK and CALL LOAD. The LOAD subprogram is actually used to load tagged object code but it can also be used to set values in memory or devices.

  • CALL LOAD(-31962,100,155)

This is address >8326; loading the values 100, 155 at those locations makes the interpreter run the program (RUN).

  • CALL LOAD(-31952,255,231,255,231)

Resets the pointers at >8330 and >8332 to FFE7 and FFE7, which wipes the program in memory (effectively a NEW).

  • CALL LOAD(-31962,100,136)

100, 136 is RESequence. This will renumber all BASIC lines (here by default start 100, increment 10)

  • CALL LOAD(-31962,160,04)

This will execute RUN without pre-scan

  • CALL LOAD(-31961, 149)

Automatic RUN DSK1.LOAD

  • CALL LOAD(-31931,0) and CALL LOAD(-31931,128)

Address >8345; turns off and on Extended Basic list protection. Only the leftmost bit is significant, so all values 0-127 are treated as 0 and 128-255 are treated as 1.

  • CALL PEEK(2,a,b):: CALL LOAD(-31804,a,b)

At location >0002 we have the program counter component of the RESET vector (usually >0024). -31804 is the address >83C4, which is the pointer to the user-defined interrupt routine. In other words, this will make the system execute a QUIT at the next interrupt. Caution: This is equivalent to pressing FCTN-=, not to entering BYE.

  • CALL PEEK(-31877,A)

At >837B (this address) we find a copy of the VDP status register which is copied there by the console interrupt service routine (ISR).

  • CALL PEEK(-31879,A)

Address >8379 contains a byte value that is incremented on each VDP interrupt (wraps at 255 back to 0)

  • CALL PEEK(-31878,A) / CALL LOAD(-31878,A)

Address >837A is the highest number of a sprite in auto-motion. You can query the number with CALL PEEK, and you can also modify it with CALL LOAD, which will cause higher sprites to stop auto-motion.

  • CALL LOAD(-31806,A)

>83C2 is a flag byte that is read by the console ISR. It is built up like this:

0 1 2 3 4 5 6 7
Enable* Sprite motion* Sound* Quit key* 0 0 0 0

(* indicated negative logic, means that the feature is on with a 0 bit and off with a 1 bit)

Accordingly we get the following settings:

A=64 (01000000): Disable sprite motion

A=0 (00000000): Enable all

A=16 (00010000): Disable QUIT key

If the Enable* bit is cleared (set to 1) we get no sprite and sound processing and QUIT key, but the VDP status is still being read and copied to >837B, the screen blanks after some time, and the interrupt counter is increased. Also, a user-defined ISR is served if registered at >83C4.

Extended Basic Tips

Pre-scan control

Pre-scan is used to allocate memory before the BASIC program starts. It causes a notable pause before the first statement executes, because the pre-scan process scans the whole program for variables and subprograms. Extended Basic allows for a quicker start-up by turning pre-scan off and on; these lines are specific comment lines.

100 GOTO 150
110 A=0 :: B$="" 
120 DATA 1
150 !@P-

turns off pre-scan after line 150

200 !@P+

turns it on after line 200. Pre-scan is enabled by default.

Pre-scan must be active for the following program parts:

  • The first DATA statement
  • The first use of a variable or an array
  • OPTION BASE (if used)
  • Reference to each subprogram called in the program
  • DEFs
  • SUB and SUBEND

Variables introduced in the SUB statement (formal arguments) are locally valid, so they must be included. CALLs in the pre-scan need not list actual arguments. You do not need to build correct assignments to variables either. However, the lines must not be executed, or an error will occur.

100 GOTO 150
110 CALL SCREEN :: CALL MYOWNSUB :: CALL CLEAR :: A,B,C=D :: E :: NAME$ :: !@P-
120 DATA 10
150 CALL CLEAR 
160 REM REST OF PROGRAM

Other Programming languages

See main article on Programming languages

Assembly programing

See also the Programming FAQ