CODINGLISTINGS ★ Bytes and Pieces ★

Byte and Pieces (The Amstrad User #7)Coding Listings
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

More useful Machine Code routines from Sydney Brown

Here are some more machine code routines which should make things faster and easier in your own basic programs. Sharp eyes would have noticed a small error in Routine #5 last month - the last line should have commenced with C9 not 69. This is , of course, in hexadecimal and you should remember that all numbers to the left of the opcodes are in this format.

Routine #1

This routine accesses the firmware routine called KM WAIT KEY which will wait until a key is pressed and then return the character or expansion taken in the A register.

Here is the source code for the routine to call from basic.

D5 PUSH DE Save variable address on stack
CD 18 BB CALL &BB 18 Call KM WAIT KEY
E1 POP HL Retrieve variable address
77 LD(HL),A Put value into variable
C9 RET Return to basic

As with two of the routines last month the value is returned and placed into an integer variable which must have previously been used.

Here is a typical example for those people who missed the previous routines.

10 A%=0 20 CODE=&4000
30 CALL CODE,@A%
40 PRINT A%

Remember before running this program you must place the data for the machine code into memory, set CODE to equal the start and move MEMORY to below the code.

Routines #2 and #3

These two routines will enable you to scroll vertically

[1] The whole screen.
[2] A section of the screen.

[1] To scroll the whole screen we will use the routine called SCR HW ROLL which stands for Hardware Roll.

This means that the actual start address of the screen RAM is increased or decreased by 80 bytes so in effect the visual screen is moved over the RAM so the data does not have to be moved around in memory.

ROLL WHOLE SCREEN DOWN

3E C8 LD A,&C8 Load colour to fill cleared line
06 00 LD B,0 Select down roll
CD 4D BC CALL &BC4D Call SCR HW ROLL
C9 RET Return to basic

The same routine can be used to roll the whole screen up, the only change is on the second line which must read:-06 01 LD B,1 Select up roll

The colour loaded into A is actually the encoded ink, so you can fill the area with solid or striped colour.

An attempted full explanation of the method of encoding inks was made in the last issue of this magazine and is much too lengthy and complex to repeat but you could experiment by placing any value from 0 to 255 into A in the first line; instead of &C8.

[2] The second scroll routine allows you to scroll a character block area of the screen up or down.

The program is a bit longer than the last routine as you must set up the top, bottom, left and right edges of the area to scroll.

This time we are going to use the routine SCR SW ROLL which stands for Software Roll.

A software roll is a bit slower than a hardware roll as all of the information on the screen, (16,384 bytes or memory positions) must be picked up one at a time and placed 80 bytes up or down through screen RAM.

SCROLL A SECTION OF THE SCREEN DOWN 3E C8 LD A,&C8 Load colour to fill cleared line
06 00 LD B,0 Select down roll
26 05 LD H,5 Left character column
2E 03 LD L,3 Top character row
16 0C LDD,&C Right character column
1E OF LD E,&0F Bottom character row
CD 50 BC CALL &BC50 Call SCR SW ROLL
C9 RET Return to basic

The colour encoding and roll direction are controlled exactly the same as the previous routine.

The co-ordinates start from 0,0, with 0,0 being the top left comer of the screen.

The area is set as follows:-

TOP-3 BOTTOM-15 RIGHT-12 LEFT-5
or &03 or &0F or &0C or &05

Routine #4

This routine will allow you to change the screen offset address, which is the address of the start of the screen with reference to the start of screen memory, &C000 or 49152 in decimal.

26 00 LD H,0 Set HL byte of offset
2E 00 LD L,0 set LO byte of offset
CD 05 BC CALL &BC05 Call SCR set offset
C9 RET Return to basic

The screen offset will only move in two byte blocks, (one mode 1 character width) and to a maximum of 16k-2 or 16382.

To split the offset into the required HI and LO bytes, use the following (e.g. OFF=the offset from zero).

HI=INT(OFF/256):LO=OFF-256*HI:POKE LOW,LO:POKE HIGH,HI:CALL OFFSET

By experimenting you will notice that pokeing LOW with 2 will move the screen backwards by one character.

You will find things easier to work with if you experiment or use the routine after a MODE command as this resets the offset to 0.

A related effect can be produced by using the OUT command in basic. The output port 511 will set the screen offset but only in program run mode. Once the computer returns to direct mode the screen will automatically return to its previous position.

This small program will show you how the port works:

10 FOR W=0 TO 80:OUT 511,W:FOR WW=1 TO 35:NEXT:NEXT:FOR W=80 TO 0 STEP-1:OUT 511,W:FOR WW=1 TO 35:NEXT:NEXT:GOTO 10

Other Snippets

Out of interest, another useful out command is OUT 512,0 which turns the cassette OFF and OUT 512,255 which turns the cassette ON.

CALL &BC71 also turns the cassette OFF and CALL &BC6E turns the cassette ON.

Here are some useful FIRMWARE ROUTINES which you activate by simply calling the required address.

CALL &BB48 - will disarm break key while the program is running but will be automatically reset in direct mode or waiting on an input command.
CALL &BB4E - will totally reset the text screen to clear, set paper to inkO and reset all inks reset to initial colours.
CALL &BB9C - will swap the current pen and paper inks. (Inverse character).
CALL &BBBA - will reset the graphics screen and colours as &BB4E does for the text screen.
CALL &BBFF - resets screen to default mode as does switch on (mode 1).
CALL &BCA7 - will reset the sound chip and clear all sound queues and enable interupts.
CALL &BCB6 - holds all sound output as is but retains all values.
CALL &BCB6 - allows sounds to continue after being held up by the previous routine.
CALL &BD19 - waits for vertical blank pulse used for animation without flicker.
CALL &BD37 - resets the original jumpblock values if you have been experimenting with redirecting the calls to your own routines.

You may find some of these memory positions useful with which to experiment;

&B1C8 contains the current screen mode.
&B4F4 contains value for joystick 1.
&B4F1 contains value for joystick 2.
&B4E9 contains value for the intial key delay
&B4EA contains value for the key repeat speed
&B1FB enables colour flashing ON=255, OFF=0

&B187) the four positions
&B188) used to store the value for
&B189) TIME and can be reset by
&B18A) pokeing any of them with 0.

&B1D7) set the on/off times
&B1D8) for the flash rate.

&B1D9 to &B1FA contain the encoded inks for border and inks 0 to 15. (Have fun with these).

The Amstrad User

★ PUBLISHER: The Amstrad User (Australia)
★ YEAR: 1985
★ AUTHOR: Sydney BROWN
 



★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listing:
» Byte  and  Pieces    (The  Amstrad  User-7)    LISTINGDATE: 2024-08-17
DL: 142
TYPE: PDF
SiZE: 446Ko
NOTE: 1 page/PDFlib v1.6

★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Coding Src's » Byte and Pieces (The Amstrad User #6)
Je participe au site:
» Pour ce titre nous ne disposons de fichier executable sur CPC (Dump, Saisie du listing) , alors si vous avez ça dans vos cartons ou vous désirez usé vos petit doigts boudinés sur votre clavier faites le nous savoir.
» Vous avez des infos personnel ?
» Vous avez remarqué une erreur dans ce texte ?
» Aidez-nous à améliorer cette page : en nous contactant via le forum ou par email.

CPCrulez[Content Management System] v8.732-desktop/c
Page créée en 074 millisecondes et consultée 672 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.