I hope you've been following me all right so far and enjoying some experimenting with the assembler - it is through trying things out that we learn and hopefully I shall lead up to providing routines for simple arcade games and also possibly adventure games too.
Having given the routines for printing to screen, etc, you should be able to make up instructions for a simple game or menu or even location data for an adventure game. How about some ideas?
In the meantime, I want to progress to some more interesting routines as promised in EUG #19.
Plotting And Drawing
These are performed by using VDU25 and PLOT becomes:
VDU 25,p,x,ywhere p is the PLOT number and x,y are the co-ordinates.
For MOVE, use PLOT 4 and for DRAW, use PLOT 5. Other PLOT numbers can be used just as in BASIC. e.g. PLOT 85 for filling triangles.
If you are setting up a series of PLOTs to draw a diagram, I've made up a subroutine which reads data in the form:
EQUB p:EQUW x:EQUW y
This needs the number of PLOTs loaded in A register and the address of the data loaded in X and Y registers, as explained for previous routines, before the routine is called.
.plot STXaddr:STYaddr+1:STAlen:LDY#0 .ploop LDA#25:JSR&FFEE \VDU25 LDX#5 .ploop2 LDA(addr),Y:JSR&FFEE \enter data byte INY:BNEnotover:INC addr+1 .notover DEX:BNEploop2 DEClen:BNE ploop RTS
Note that there are two variables in this listing which should be allocated before the assembly loop so add:
15 addr=&70:len=80
You may also add the address of OSWRCH as a variable since it's easier to write and saves remembering the address. Add:- oswrch=&FFEE to line 15. This could even be shortened further (e.g. os) provided it does not clash with other variables.
It is usually good practice to allocate any variables in this way at the beginning of the program.
The subroutine first enters the value 25 before calling OSWRCH then enter the loop 'ploop2' which repeats five times to enter the five data bytes. The variable 'len' is then decremented and if not zero then the routine branches back to 'ploop1' for the next plot. If the data is longer than 255 bytes, Y register will return to zero and the branch to 'notover' will not occur so that the high byte of 'addr' is incremented.
The Print routine could be modified in a similar way to enable it to print longer text as it will only print up to 255 characters at present.
User Defined Characters
These are defined by VDU23,char,a,b,c,d,e,f,g,h as in BASIC and this routine will set up any number of characters (from 224 in sequence).
It will read a series of data lines in the same way as the above routine. The data can be entered, following the label '/.chardata', as:
EQUB a:EQUB b:EQUB c:...........EQUB h
This can be simplified by using EQUD:EQUD but the numbers must be in hex and each four digits must be entered in reverse order as EQUD enters them in reverse order. This then becomes:
EQUD &dcba:EQUD &hgfe
This routine needs the variables, temp=&81 and oswrch=&FFEE. Enter them in line 15 as mentioned above.
.chars LDY#0:LDX#224 .chloop1 STXtemp LDA#23:JSRoswrch \VDU23 TXA:JSRoswrch \character no. LDX#8 .chloop2 LDAchdata,Y \read data byte JSRoswrch INY DEX BNEchloop2 LDXtemp \reload char no. INX \increment char no. CPX#242 \last char no. +1 BNEchloop1 RTS
X register is loaded with 224, the first character value and this is stored in 'temp' within loop 'chloop1' since X register is used in the second loop to count the 8 data bytes. A register is first loaded with 23 then the value in X to give the first two parts of the command. The loop 'chloop2' then loads the 8 data bytes. Register X is then loaded from 'temp' and incremented before repeating the process for the next character. When the final character definition is completed, the routine does not branch back as the comparison is met. The value of this must be entered according to the number of characters to be defined.
This routine uses the Indexed Addressing mode and as written can only be used once in the program. If some characters need to be redefined during the running of a program, it should be possible to re-write the code in a similar way to he print routine so that some could be redefined from a second set of data. How about trying this? You would need to do the characters in reverse order - say from 250 down to 224 and from say 230 to 224 to re-define these. I will cover this later if needed.
I hope to cover key entry routines for making menu choices and moving characters about the screen next time.
Richard Dimond, EUG #20