Welcome, Guest. Please login or register.


Author Topic: Graphics Attribute Mode Example (Read 6645 times)

Offline jonesypeter

  • Newbie
  • Posts: 19
  • Country: gb
Graphics Attribute Mode Example
« on: 2020.October.02. 12:34:33 »
Hello,

I'm coming from a ZX Spectrum background, and wondered if anyone could give me an example in BASIC of using the 'Graphics Attribute' mode? I looked in the manual, but can't see any examples.

Also, is there the equivalent of the Spectrum ATTR (X,Y) command which is useful when writing games in BASIC to find the attributes of a cell at a particular position.

Many thanks

Peter

Offline szipucsu

  • Global Moderator
  • EP addict
  • *
  • Posts: 9898
  • Country: hu
    • Támogató Támogató
    • Webnyelv.hu - Tanuljunk nyelveket!
Re: Graphics Attribute Mode Example
« Reply #1 on: 2020.October.02. 14:02:51 »
A game that uses attribute mode is Gombócfaló by Attus. You can download it here, in .rar format. There are a lot of basic programs here, you have to look at GOMBOCF.BAS in the rar pack.

I don't know the Spectrum's ATTR() command. You may look for the command LOOK #chan:AT X,Y. However it gives you the colour of a pixel, not the code of a character. You can handle the attribute screen both as a text window and as a graphical window and the two types of windows can be referret to in a different way. (So, X,Y will be very different if you PRINT AT X,Y and if you draw using PLOT X,Y.)
100 SOUND SOURCE 2,STYLE 128,PITCH 25.2,SYNC 1
110 SOUND PITCH 25,SYNC 1
120 ! Videos

Offline jonesypeter

  • Newbie
  • Posts: 19
  • Country: gb
Re: Graphics Attribute Mode Example
« Reply #2 on: 2020.October.02. 15:05:28 »
Thank you szipucsu

How do I load .bas files into ep128emu please?

Thanks

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Graphics Attribute Mode Example
« Reply #3 on: 2020.October.02. 15:11:23 »
On the menu Options/Set working directory, select the directory where you have the files.

On the menu File/Configuration/Load from ASCII file, select one of the configurations(on the EP12emu/Config directory) that include "FileIO" at the end of the name. The emulated EP will reset itself.

Then on Basic, you must execute LOAD "", without file name, to force the emulator to show a file manager from which you can select your file. All programs will use the directory as the default storage unit.
« Last Edit: 2020.October.02. 15:31:27 by gflorez »

Offline jonesypeter

  • Newbie
  • Posts: 19
  • Country: gb
Re: Graphics Attribute Mode Example
« Reply #4 on: 2020.October.02. 16:00:18 »
Thank you, that worked.

I looked at the look command and that is not quite what I'm looking for.  What I'm after is being able to find what character code is at an x,y print position. 

Something like this:

So start with this:
PRINT AT 11,16;"*"

Then

SCREEN$ is the reverse function to PRINT AT, and will tell you (within limits) what character is at a particular position on the screen. It uses line and column numbers in the same way as PRINT AT, but enclosed in brackets: for instance PRINT SCREEN$ (11,16) would print "*", which you could assign to a variable.

It allows for basic collision detection is BASIC.

Thanks

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Graphics Attribute Mode Example
« Reply #5 on: 2020.October.02. 17:19:28 »
The right way is the one that Szipucsu has pointed, but the graphics screens, and Attribute mode is graphics, return the palette colour on the pixel. The text screens return the character on the text coordinates with the same LOOK command.

[ Guests cannot view attachments ]

Still there is an option: create a 2 dimensions string matrix with the same measures, and print on it the same characters that you have put on the real screen. To clear the matrix very fast you only need to close it and re-define it again.
« Last Edit: 2020.October.02. 17:26:11 by gflorez »

Offline szipucsu

  • Global Moderator
  • EP addict
  • *
  • Posts: 9898
  • Country: hu
    • Támogató Támogató
    • Webnyelv.hu - Tanuljunk nyelveket!
Re: Graphics Attribute Mode Example
« Reply #6 on: 2020.October.03. 11:34:57 »
What I'm after is being able to find what character code is at an x,y print position.  
...
PRINT AT 11,16;"*"
...
PRINT SCREEN$ (11,16) would print "*", which you could assign to a variable.
Unfortunately attribute mode is rather a graphical mode than a text mode. So in attribute mode there is not a simple solution for this. As GFlorez wrote you should ask for the pixel colour of the character's position. (However it seems difficult as character X,Y position is stored differently from the pixel X,Y position. The game Gombócfaló linked above solves this in some way but I don't know how.) I would rather create a matrix that Gflorez wrote so if you print something you should fill the parallel content of the matrix, e.g. PRINT AT 3,5:"B":LET SC$(3,5)="B".

If you do not use attribute mode but text mode you can solve it easily:
PRINT #chan:AT 3,5:;
GET #chan:A$
So you can get the character.

Other suggestion: you can use 4-colour character mode instead of attribute mode and you can use the easier method. However you have only 3+1 colours. I still prefer 4-colour character mode to attribute mode because I can have character animation. In an attribute screen characters are printed on the screen but they are no more considered characters, they are only some group of pixels as any other graphic item. They cannot be overwritten by space characters. You have to switch to the background colour, print a character full of pixel so you can remove your character from the attribute screen. It is somewhat slow but you can use Zzzip compiler for higher speed.
100 SOUND SOURCE 2,STYLE 128,PITCH 25.2,SYNC 1
110 SOUND PITCH 25,SYNC 1
120 ! Videos

Offline tofro

  • Beginner
  • *
  • Posts: 31
  • Country: de
Re: Graphics Attribute Mode Example
« Reply #7 on: 2020.October.03. 12:02:21 »
Well, in general, you shouldn't regard screen memory as your data store - I'm sure your program knows the position of things in other places (like "PlayerX, playerY",...) as well. If you are doing collision detection based on these positions, you might be better off for all possible modes.

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Graphics Attribute Mode Example
« Reply #8 on: 2020.October.03. 12:46:28 »
There is another tricky way... Knowing the LPT address, the text buffer address can be found on one of the lines,  and with the use of SPEEK and a simple formule you can know the character on the text coordinate.

Offline dangerman

  • EP fan
  • *
  • Posts: 100
Re: Graphics Attribute Mode Example
« Reply #9 on: 2020.October.03. 13:07:26 »
They cannot be overwritten by space characters.

Actually, it seems that in ATTRIBUTE mode, you can overwrite by printing with space characters. Although that doesn't work in the other graphics modes, only in attribute mode.

Offline szipucsu

  • Global Moderator
  • EP addict
  • *
  • Posts: 9898
  • Country: hu
    • Támogató Támogató
    • Webnyelv.hu - Tanuljunk nyelveket!
Re: Graphics Attribute Mode Example
« Reply #10 on: 2020.October.03. 13:56:39 »
in ATTRIBUTE mode, you can overwrite by printing with space characters
Wow, you are right. I have just tried it.

Knowing the LPT address, the text buffer address can be found on one of the lines,  and with the use of SPEEK and a simple formule you can know the character on the text coordinate.
Yes, but it does not work with the attribute mode, only with the pure text modes. (I think.) It is an alternative for GET #chan:A$ and is faster.
« Last Edit: 2020.October.03. 14:00:57 by szipucsu »
100 SOUND SOURCE 2,STYLE 128,PITCH 25.2,SYNC 1
110 SOUND PITCH 25,SYNC 1
120 ! Videos

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Graphics Attribute Mode Example
« Reply #11 on: 2020.October.03. 16:02:51 »
Yes, you are right... the buffer zones of the attribute mode are pixel and attr., not text.

Off topic: The Amstrad CPC is a totally graphic computer, it doesn't have a text mode nor a buffer, but can emulate it. There is a Rom function that returns the value of a character given certain coordinates. A workaround is used: the rows of bytes that are found on the coordinates(on text boundaries) are compared with all the ones on the character set until a match is found.


Offline szipucsu

  • Global Moderator
  • EP addict
  • *
  • Posts: 9898
  • Country: hu
    • Támogató Támogató
    • Webnyelv.hu - Tanuljunk nyelveket!
Re: Graphics Attribute Mode Example
« Reply #12 on: 2020.October.03. 18:48:56 »
The Amstrad CPC
There is a Rom function that returns the value of a character given certain coordinates. A workaround is used: the rows of bytes that are found on the coordinates(on text boundaries) are compared with all the ones on the character set until a match is found.
It is interesting, I didn't know that! This is why editing seems so complicated for me: I cannot simply go back to the previous line to edit it and press enter again, I think.
If so: what happens if you redefine the character set? The rows of bytes cannot be compared with the rows of the character set. You could define the same shape to more than one character, it can mislead the machine. Or, maybe, there is no option to redefine characters and "problem solved".
100 SOUND SOURCE 2,STYLE 128,PITCH 25.2,SYNC 1
110 SOUND PITCH 25,SYNC 1
120 ! Videos

Offline tofro

  • Beginner
  • *
  • Posts: 31
  • Country: de
Re: Graphics Attribute Mode Example
« Reply #13 on: 2020.October.03. 19:16:53 »
There is a Rom function that returns the value of a character given certain coordinates. A workaround is used: the rows of bytes that are found on the coordinates(on text boundaries) are compared with all the ones on the character set until a match is found.

Which is of course not exactly blazingly fast.... That ROM function needs to scan through the whole character set worst case.

Offline dangerman

  • EP fan
  • *
  • Posts: 100
Re: Graphics Attribute Mode Example
« Reply #14 on: 2020.October.03. 20:29:41 »
Off topic: The Amstrad CPC is a totally graphic computer, it doesn't have a text mode nor a buffer, but can emulate it. There is a Rom function that returns the value of a character given certain coordinates. A workaround is used: the rows of bytes that are found on the coordinates(on text boundaries) are compared with all the ones on the character set until a match is found.

I think this is probably what the Spectrum does as well with the SCREEN$ command. The Spectrum display is not a text buffer either. It's an attribute-based graphical display.