www.finchpj.co.uk

Bono Vince Malum (Overcome Evil with Good )

Basex

 

 

Home
Up
NHS Practice
Personal
PDTronics

From Your Commodore, April 1989, 58-59 ;67-72

Basex - Soup up your 64 with this new Basic Enhancer
By Peter Finch

BASEX - or BASIC extension is an 8K machine code program residing in memory from $8000 to $9FFF above Basic. It extends the crude Basic resident on the Commodore 64, and enables the user to utilise the powerful hardware capabilities of this machine, without the need for numerous complicated POKE statements to locations which must either be memorized (!), or looked up in a reference manual.

Furthermore, the default memory map is reorganised to utilise the (normally unused) shadow RAM, hidden behind the ROMs, for the memory-expensive high-resolution graphics screen, leaving more Basic bytes free. The complete character set is user-definable, and is also located in shadow RAM.

BASEX is used in the form of keywords, and operators which are tokenised in the same way as Basic. As with Basic, an abbreviated entry of the first few letters and a shifted letter is acceptable and will save time.

The utilities cover four areas:

1. Sound generation by the SID chip.
2. Graphics produced by the VIC chip.
3. A disk monitor.
4. Programming structures including function key definitions.

The Commodore operators are extended to include hexadecimal, binary, label variables with more than two significant letters, and numeric output with tabulated decimal places. In addition, there is a full two pass labelling assembler used from Basic, which even allows conditional assembly. Other machine code utilities include a disassembler, memory display in hex and ASCII, memory load and save.

 [ ] = optional parameters, n = numeric parameter, s$ = string
[Back to contents]

1 Sid Chip Control

SOUND Define general sound volume and filters.
Syntax: SOUND 0 disable SID 
SOUND nl, n2 [,n3, n4, n5] 
nl filter mode 0-15 (1 low pass, 2 band pass, 4 high pass, 8 voice 2 off; can be additive eg. 5 notch reject = low + high).
n2 volume 0-15.
n3 filter resonance 0-15.
n4 filter voice 0-15 (1 voice 0, 2 voice 1, 4 voice 2, 8 external).
n5 filter cut-off frequency 0 (=30Hz) - 2047 (=20 K Hz).

ENVELOPE Define envelope for each voice.
Syntax: ENVELOPE nl, n2, n3, n4, n5, n6
nl voice number 0-2.
n2 attack 0-15.
n3 decay 0-15
n4 sustain 0-15.
n5 release 0-15.
n6 pulse width 0 - 4095 (proportion of pulse high eg. 2047=50%).

VOICE Produce sound of certain pitch and timbre.
Syntax: VOICE nl, n2 [, n3, n4, n5]
n1 voice number 0-2.
n2 frequency 0-65535 (= Hz *16.77216).
n3 waveform 1-8 ( 1 triangular, 2 sawtooth, 4 pulse, 8 noise).
n4 special effects 0-2 ( 1 synchronise, 2 ring modulate).
n5 duration 0-255 (=seconds*50).
Note: Use full syntax for first sound, thereafter can use short form to change frequency eg. in glissando.  End of sound can be detected by PEEK($335 + nl) = 0
[Back to contents]

2 VIC Chip Control

(Colour parameters 0 black, 1 white, 2 red, 3 cyan, 4 purple, 5 green, 6 blue, 7 yellow, 8 orange, 9 brown, 10 light red, 11 grey1, 12 grey2, 13 light green,14 light blue, 15 grey3).

MODE Change screen mode.
Syntax: MODE 0, nl Text, background n1.
MODE 1, n1, n2 Graphics, background n1, cursor n2.
MODE 2, n1, n2, n3 Multicolour text, background n1, cursor1 n2, cursor2 n2.
MODE 3, nl, n2, n3 Multicolour graphics, background n1, cursor1 n2, cursor2 n3.
MODE 4,n1,n2,n3,n4, Extended text, background1 n1, background2 n2, background3 n3, background4 n4.

CLS Clear the text screen. (Will alter graphics colours).

CLG Clear the graphics screen. (Will obliterate characters in text mode).

CSR Change cursor color
Syntax: CSR n (n=0-15 in text mode, 1-3 in mode 3)

EDGE Change screen border.
Syntax: EDGE n (n=0-15).

SCROLL Scroll text screen.
Syntax: SCROLL n (n=0 up, 1 down, 2 left, 3 right)

BAR Draw a vertical bar in text mode.
Syntax: BAR n1, n2
n1 Horizontal displacement 0-39.
n2 Vertical displacement 0-199.

PLOT Plot a point on screen.
Syntax: PLOT nl, n2
n1 Horizontal axis 0-79 text mode, 0-319 mode 1, 0-159 mode 3.
n2 Vertical axis 0-49 text mode, 0-199 graphics mode.

DRAW Draw a straight line from last point plotted.
Syntax: DRAW nl,n2
Parameters as for PLOT.

CIRCLE Draw a circle (ellipse in mode 3).
Syntax: CIRCLE nl,n2,n3 
n1 Radius, n2,n3, X,Y position of centre.
Parameters as for PLOT

FILL Fill graphics screen area within plotted boundary
Syntax: FILL nl,n2
Fill starting from position n1,n2 =X,Y.

MOB Define a movable object block (sprite).
Syntax: MOB n1 (de-activate MOB n1)
MOB n1,n2,n3,n4,n5[,n6,n7].
n1 MOB number 0-7.
n2 MOB data address in Bank 3 0-255 ($C000+n2*$40).
n3 Expansion 0-3 (1 Y expanded, 2 X expanded, 3 both).
n4 Priority 0 Data > MOB, 1 MOB > data.
n5 Colour.
n6 Colour2 (Multicolour MOB).
n7 Colour3.

MOVE Move a MOB.
Syntax: MOVE nl,n2,n3
nl MOB number 0-7
n2 Horizontal position (0-320 visible).
n3 Vertical position (29-229 visible).
[Back to contents]

3 Disk Monitor

DISK Access disk monitor with directory ($) and usual commands (C, I, N, S, UJ, V). X to exit. Status = < CR > alone. 
Syntax: DISK n
n defines the device number (usually 8).
[Back to contents]

4 Programming Features

APPEND Append a program to that already in memory. 
Syntax: APPEND s$, nl Load file s$ from device n1.

AUTO Automatic line numbering.
STOP to escape. 
Syntax: AUTO [nl, n2] 
nl Interval (default 10)
n2 First line number (default 10).

DELETE Delete line numbers within range. 
Syntax: DELETE nl,n2

DUMP Screen dump to printer.
Note: requires OPEN 4,n to printer.  Assumes Epson type for graphics

KEY Define function keys. (Fl set TAB). 
Syntax: KEY nl (clear function key n1
KEY nl, s$[¬] 
nl Function key number 2-8
s$ String definition (max length 8)
[¬] Automatic carriage return.

PIC Define decimal places for output with ! 
Syntax: PIC nl decimal places 0-9.

RENUMBER Line renumber (including GOTO/GOSUB etc). 
Syntax: RENUMBER [nl, n2] 
nl Interval (default 10).
n2 First line number (default 10)

REPEAT: UNTIL/WHILE (condition)  Structured programming.
Example:
J=0: REPEAT: PRINT J: J=J+l: UNTIL J=10
J=0: REPEAT: PRINT J: J=J+l: WHILE J< 10
[Back to contents]

Operators

PRINT@ nl,n2,s$ Prints string s$ at row nl, column n2.
PRINT Łn1 Outputs n1 as a hexadecimal string.
PRINT !n1 Outputs n1 as string with tabulated decimal.
PRINT $s$ Outputs hex string s$ as numeric variable.
PRINT %s$ Outputs binary string s$ as numeric variable.
PRINT .NAME Outputs label from assembler as numeric variable.
[Back to contents]

User Defined Graphics

The character set is defined in shadow RAM starting at $E000, and may be redefined as required. This area of memory appears to be write-only because of the shadow effect, thus reading it will give erroneous values. A redefinition is conveniently performed in hexadecimal using the 8 byte poke with "*:". For example the Commodore logo can be defined at $E000 and will appear instead of@. Note however that this character will still be treated in exactly the same way as @

$E000 00011100 $1C
$E001 00110110 $36
$E002 01100111 $67
$E003 01100000 $60
$E004 01100111 $67
$E005 00110110 $36
$E006 00011100 $1C
$E007 00000000 $00
*:E000 1C 36 67 60 67 36 1C 00
[Back to contents]

Machine Code Features

*ASS Commence two pass labelling assembler.
Syntax: *ASS nl
Commence assembly at address nl , terminated by *END. Assembler code can include complex operands, including labels which must be signified by .name; such code must be tokenised. However, tokenisation of opcodes (eg AND, ORA) and labels must be suppressed by REM (which is ignored). Note the use of EQU - a DB/DS to define bytes or string in memory. Characters to the right of ; are ignored. Labels are assigned the value 65535 ($FFFF) onfirst pass - thus .LABEL+1 will fail unless the label has been assigned before the reference.
Example:
10 ma=$7F : lo=$C000 : REM mask, location (only first 2 letters significant)
20 *ASS $C800
30 .START LDA .MESSAGE/256 : LDY $C8 ; Ignore this
40 REM AND mask : STA location
50 REM RTS
60 .MESSAGE EQU $93, "This is a message",13,$D
70 *END
80 SYS .START :REM Call this (nonsense) program

*DIS Disassemble machine code.
 Syntax: *DIS nl[,n2]
 Disassemble memory contents from nl to n2, a page at a time.

*LOAD Load code without disturbing BASIC pointers.
 Syntax: *LOAD s$,nl
 Load file s$ from device nl to header address.

*MEM Display memory in hexadecimal and ASCII.
 Syntax: *MEM nl[,n2]
 Display memory contents from address nl to n2

 *SAVE Save code from anywhere in memory.
 Syntax: *SAVE s$,n1,n2,n3
 Save file s$ on device n1, from address n2to n3

*: Eight byte hexadecimal POKE.
 Syntax: *:C000 AA 55 AA 55 AA 55 AA 55
 Poke the eight hexadecimal bytes to memory (here to $C000)

Back to Top

Home ] Up ]