CPCWiki forum

General Category => Programming => Topic started by: TCMSLP on 22:06, 12 November 12

Title: Help: Screen ram layout?
Post by: TCMSLP on 22:06, 12 November 12
Hi All,

I've just started taking my first steps in Z80 and thought playing with the video ram would be an excellent way to see the effects of my code.

Having read that the screen memory is not laid out too sanely, I checked The Amstrad CPC Firmware Guide (pages 30-31) for clues.  I think (?) it states that mode 2 is the simplest with each bit mapping to a single (I assumed consecutive) pixel.  Great!

So, I compile this using JavaCPC:-


org &6000

SCR_SET_MODE EQU &BC0E

ld a, 2                       ; mode 2
call SCR_SET_MODE

ld a, $111111            ; byte to write
ld hl, $c000       ; start of screen ram

.loop
ld (hl), a         ; set byte to $11111111
inc hl                      ; increment hl
jp loop


Yes, I realise it loops forever.  I was about to implement a counter to count down from 16384 however it seems everything I try to do results in running out of registers.   

Anyway, run the above and I get stripes.  The CPC Firmware guide doesn't seem to explain this.  Although, it does describe moving down/up a line or right/left a character by incrementing +/- &02 and +/- &50.  When printing one byte with these offsets, this seems to be correct.   However, my $11111111 always results in stripes.

Clearly I'm missing something obvious here.   Can anyone point me in the right direction?
Title: Re: Help: Screen ram layout?
Post by: ralferoo on 23:27, 12 November 12
It's just a not very good assembler. It should be warning you that $11111111 is overflowing the A register - it's being truncated to $11, or in binary 00010001. What you want is $FF.
Title: Re: Help: Screen ram layout?
Post by: TCMSLP on 23:41, 12 November 12
Argh yes, I shouldn't work on this when tired. I meant to use %11111111. *head desk*

Thanks :)
Title: Re: Help: Screen ram layout?
Post by: Devilmarkus on 23:41, 14 November 12
$ is used like &.

You need to use the % sign:

org &6000

SCR_SET_MODE EQU &BC0E

ld a, 2                       ; mode 2
call SCR_SET_MODE

ld a, %111111            ; byte to write
ld hl, $c000       ; start of screen ram

.loop
ld (hl), a         ; set byte to %11111111
inc hl                      ; increment hl
jp loop


Edit: Your answer was faster :P
Title: Re: Help: Screen ram layout?
Post by: Devilmarkus on 23:44, 14 November 12
Quote from: ralferoo on 23:27, 12 November 12
It's just a not very good assembler. It should be warning you that $11111111 is overflowing the A register - it's being truncated to $11, or in binary 00010001. What you want is $FF.

True... the integrated Z80 assembler in JavaCPC is very basic... But should be ok for the most quick things ;)
As I don't know assembler, it was hard to create an assembler interpreter and compiler...
Title: Re: Help: Screen ram layout?
Post by: ralferoo on 13:07, 15 November 12
Quote from: Devilmarkus on 23:44, 14 November 12
True... the integrated Z80 assembler in JavaCPC is very basic... But should be ok for the most quick things ;)
As I don't know assembler, it was hard to create an assembler interpreter and compiler...
Sorry, I didn't mean to criticise too much and "bad" was probably the wrong word. I just meant that a 32-bit value is never going to fit into an 8-bit register and that's the kind of thing most compilers and more often that not assemblers warn you about...

But don't get me wrong, any kind of embedded assembler in an emulator is massively useful! :)
Title: Re: Help: Screen ram layout?
Post by: Devilmarkus on 13:49, 15 November 12
No worries ;)
I know what you wanted to say ;)
Powered by SMFPacks Menu Editor Mod