Author Topic: How to get screen MODE?  (Read 1156 times)

0 Members and 1 Guest are viewing this topic.

Offline litwr

  • CPC664
  • ***
  • Posts: 144
  • Country: ru
    • lidovski's www page
  • Liked: 113
How to get screen MODE?
« on: 23:11, 11 September 16 »
What is the best way to get it?  I am going to use PEEK(&b7c3)... However it will not work with CPC464 or maybe with PLUS models.  :( Thanks.

Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 500
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 480
Re: How to get screen MODE?
« Reply #1 on: 23:17, 11 September 16 »
not sure if it works on all cpc, but this may help:

CALL &BC11
SCR GET MODE
ActionGets the current screen mode
EntlyNo entry conditions
ExitIf the mode is 0, then Carry is true, Zero is false, and A contains 0; if the mode is 1, then Carry is false, Zero is true, and A contains 1; if the mode is 2, then Carry is false, Zero is false, and A contains 2; in all cases the other flags are corrupt and all the other registers are preserved

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.435
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 692
Re: How to get screen MODE?
« Reply #2 on: 12:29, 12 September 16 »
I'm assuming @litwr wants to get the screen mode without using the Firmware, though those Addresses mean nothing if the Firmware is disabled, though I was wondering how one detects which CPC is being used years ago, which this thread has a pile of answers in it.
* Using some of the hardly used Amstrad compilers :D
* I use Firmware in my Assembly code :P
* Have interpreted some BASIC 1.1 programs for BASIC 1.0. :)

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 786
  • Liked: 343
Re: How to get screen MODE?
« Reply #3 on: 13:50, 12 September 16 »
I'm assuming @litwr wants to get the screen mode without using the Firmware, though those Addresses mean nothing if the Firmware is disabled, though I was wondering how one detects which CPC is being used years ago, which this thread has a pile of answers in it.
You can't find out from the hardware, the only way is to keep track of what value you last sent to the gate array (which is how the firmware call knows). If you need to know what mode you're in from something that is going to disable the firmware (but doesn't reset the mode itself) then you'll need to call SCR GET MODE before disabling the firmware and then keep that value up to date yourself.

Offline litwr

  • CPC664
  • ***
  • Posts: 144
  • Country: ru
    • lidovski's www page
  • Liked: 113
Re: How to get screen MODE?
« Reply #4 on: 13:54, 12 September 16 »
I want to get this mode inside Basic program.  The call to &BC11 looks a bit difficult... How to use these flags in Basic?  It is a bit odd that fine Locomotive Basic misses a useful statement. :( Commodore Basics above 3.5 have RGR statement for this.

Offline CECPC

  • CPC464
  • **
  • Posts: 37
  • Country: es
  • Liked: 18
Re: How to get screen MODE?
« Reply #5 on: 14:19, 12 September 16 »
I want to get this mode inside Basic program.  The call to &BC11 looks a bit difficult... How to use these flags in Basic?  It is a bit odd that fine Locomotive Basic misses a useful statement. :( Commodore Basics above 3.5 have RGR statement for this.
If the address is common for all CPC Basic versions...

CpcAlive is a programming environment Amstrad CPC compatible.

Then &B7C3 should cointain MODE value.
Try with PEEK(&B7C3)

In any case, Firmware routine seems more secure. With a small assembler in the basic (memory+pokes) you should be able to read the value.

Offline SuTeKH/Epyteor

  • 6128 Plus
  • ******
  • Posts: 1.237
  • Country: se
  • Epyteor - THE Amstrad Chiptune Coverband!
  • Liked: 1119
Re: How to get screen MODE?
« Reply #6 on: 14:22, 12 September 16 »
I want to get this mode inside Basic program.  The call to &BC11 looks a bit difficult... How to use these flags in Basic?  It is a bit odd that fine Locomotive Basic misses a useful statement. :( Commodore Basics above 3.5 have RGR statement for this.
Try this... I've tested it on my own 6128 (and WinAPE), but not on any other CPC!

Code: [Select]
10 MODE 1
20 FOR Address=&A000 to &A007
30 READ Byte$
40 POKE Address,VAL("&"+Byte$)
50 NEXT Address
60 CALL &A000
70 ScreenMode=PEEK(&A007)
80 PRINT "MODE";ScreenMode
90 END
100 DATA CD,11,BC,32,07,A0,C9,00

Change line 10 to whichever MODE you want to test! ENJOY!

EDIT: The assembler code incase anyone is wondering! (Not as if it's difficult to work out! ^_^)

Code: [Select]
        org    &a000

        call    &bc11
        ld    (Address),a
        ret

.Address    defb    &00
« Last Edit: 14:40, 12 September 16 by SuTeKH/Epyteor »

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 786
  • Liked: 343
Re: How to get screen MODE?
« Reply #7 on: 14:49, 12 September 16 »
Well, it looks like SuTeKH has beaten me to it, but I'll post my version as the M/C is fully relocatable which might be useful to some.

Code: [Select]
10 gosub 9000 : rem setup routine
20 let m% = 0
30 call getmode, @m%
40 print m%
50 end
9000 symbol after 256
9010 let getmode = himem - 11
9020 memory getmode -1
9030 restore 9090
9040 for i% = 0 to 10
9050 read x%
9060 poke getmode + i%, x%
9070 next i%
9080 return
9090 data &cd,&11,&bc,&dd,&6e,&00,&dd,&66,&01,&77,&c9

And the assembly:
Code: [Select]
call &bc11
ld l,(ix+0)
ld h,(ix+1)
ld (hl),a
ret

Offline PulkoMandy

  • 464 Plus
  • *****
  • Posts: 334
  • Country: fr
  • Liked: 265
Re: How to get screen MODE?
« Reply #8 on: 15:04, 12 September 16 »

And here is a "pure BASIC" solution, just for fun:

Code: [Select]
10 POKE &C000,0
30 PLOT 0,400,15
40 a=PEEK(&C000)


This will make the firmware draw a pixel at the top left of the screen, using pen 15. Depending on the mode, the byte will have different values. We then read it using PEEK, and we test the value (&80 for mode 2, and I think &88 for mode 1 and &AA for mode 0).

Offline Urusergi

  • CPC6128
  • ****
  • Posts: 157
  • Country: es
  • Liked: 234
Re: How to get screen MODE?
« Reply #9 on: 17:05, 12 September 16 »
A great trick  8) but it's out of range:

Code: [Select]
10 POKE &C000,0
30 PLOT 0,399,15
40 a=PEEK(&C000)

Offline litwr

  • CPC664
  • ***
  • Posts: 144
  • Country: ru
    • lidovski's www page
  • Liked: 113
Re: How to get screen MODE?
« Reply #10 on: 19:18, 12 September 16 »
Thanks!  :) However it would be a bit better to have a proper word in Basic.  ;)

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.435
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 692
Re: How to get screen MODE?
« Reply #11 on: 22:33, 12 September 16 »
You can't find out from the hardware, the only way is to keep track of what value you last sent to the gate array (which is how the firmware call knows). If you need to know what mode you're in from something that is going to disable the firmware (but doesn't reset the mode itself) then you'll need to call SCR GET MODE before disabling the firmware and then keep that value up to date yourself.

Looking at all the replies it appears there's all sorts of tricks you could do to find out the screen mode.  :)
* Using some of the hardly used Amstrad compilers :D
* I use Firmware in my Assembly code :P
* Have interpreted some BASIC 1.1 programs for BASIC 1.0. :)

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.313
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2191
Re: How to get screen MODE?
« Reply #12 on: 22:39, 12 September 16 »
Thanks!  :) However it would be a bit better to have a proper word in Basic.  ;)
i there a basic command to make a sprite and move it on the screen in commodore basic?
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 786
  • Liked: 343
Re: How to get screen MODE?
« Reply #13 on: 22:48, 12 September 16 »
Thanks!  :) However it would be a bit better to have a proper word in Basic.  ;)

I assume the thinking was that since the graphics commands in Basic are meant to be resolution independent, there would be little call for actually knowing the screen mode via a command.

Looking at all the replies it appears there's all sorts of tricks you could do to find out the screen mode.  :)

They all fundamentally rely on the fact the firmware is keeping track of the mode, if it wasn't then PLOT wouldn't be able to write different values to the display depending upon the current mode. The hardware itself doesn't provide any mechanism for determining a change "after the fact"

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 786
  • Liked: 343
Re: How to get screen MODE?
« Reply #14 on: 22:51, 12 September 16 »
i there a basic command to make a sprite and move it on the screen in commodore basic?

POKE. :P

But then the C64 doesn't actually have any graphics commands in basic at all! Things like RGR appear on later machines like the Plus 4, which didn't have sprites IIRC.

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.313
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2191
Re: How to get screen MODE?
« Reply #15 on: 23:15, 12 September 16 »
POKE. :P

But then the C64 doesn't actually have any graphics commands in basic at all! Things like RGR appear on later machines like the Plus 4, which didn't have sprites IIRC.
exactly!

CPC Basic lacks RGR, and Commodore BASIC lacks basic commands for sprites!
So neither BASIC is perfect.  :D



My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.435
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 692
Re: How to get screen MODE?
« Reply #16 on: 03:24, 13 September 16 »

They all fundamentally rely on the fact the firmware is keeping track of the mode, if it wasn't then PLOT wouldn't be able to write different values to the display depending upon the current mode. The hardware itself doesn't provide any mechanism for determining a change "after the fact"

Yep, so the screen mode would have to be obtained before disabling the firmware. Normally you would only do this if you wanted to return back to BASIC in the mode it was in usually. Using the hardware has little need for it, which I presume the reason why it hasn't got it.
* Using some of the hardly used Amstrad compilers :D
* I use Firmware in my Assembly code :P
* Have interpreted some BASIC 1.1 programs for BASIC 1.0. :)

Offline litwr

  • CPC664
  • ***
  • Posts: 144
  • Country: ru
    • lidovski's www page
  • Liked: 113
Re: How to get screen MODE?
« Reply #17 on: 20:28, 14 September 16 »
i there a basic command to make a sprite and move it on the screen in commodore basic?
C16/+4 have no hardware sprites  (so as CPC6128).  C128 Basic has such commands.  Locomotive Basic is fast but misses several good commands.
I used CPC6128, PCW8256 and PCW9512.   :)  They are good PC, maybe the best z80 based PC.  The problem of 6502/6809 based PC that they might be better but were often restricted artificially.  For example, C128 might be 2 times faster and use 256 KB memory.  Z80 had much better support...  IMHO it was a bit unfair.

Offline ZbyniuR

  • CPC6128
  • ****
  • Posts: 287
  • Country: pl
  • 6128 A1230 PSX Win7
    • Jedyne polskie forum o CPC. :)
  • Liked: 266
Re: How to get screen MODE?
« Reply #18 on: 18:51, 17 September 16 »
Pure BASIC solution for any CPC:

10 IF PEEK(&BB5B)=0 THEN m=PEEK(&B1C8) ELSE m=PEEK(&B7C3)

TREK is better than WARS.