>Hi,

Hello,

>       I received SC-ASM the other day, and being not ill acquainted with z80
>assembler and the workings of the ZX Spectrum, I've programmed a few
>basic things. You know, like pressing different keys activating
>different border colours and little things like that. I therefore notice
>that port 0xfe still does a lot of the same old Spectrum stuff.

Yes, 254 (dec) is still the BORDER output port, but with a few differences;
most importantly that you can set the border colour to be between 8 and 15
by setting bit 5, and that you can turn off the screen (in modes 3 and 4)
by setting bit 7. More about that later.

>       Now I want to do something better! Like a sprite moving around or
>something.

Cool. Demos are always a good place to start   :)

>So, I am wondering - what port & by what method would I page
>memory in and out?

Right, this is going to sound a bit complicated..... you'll get used to it
sooner or later :)

The Sam's 512K RAM is arranged in 32 pages of 16K each. The ROM comes in
two 16K sections, which go in sections A and D. As far as BASIC is
concerned, 16384 is the start of RAM page 0.

You can page any two consecutive pages into Z80 addresses 0 -> 32767 (Low
Memory, sections A and B), and any two consecutive pages into Z80 addresses
32768 -> 65535 (High Memory, sections C and D).

To page RAM into high memory, just output the first page number to bits
0->4 of HMPR = 251 dec (keep bits 5 -> 7 zero, they control external memory
and an obscure CLUT feature in Mode 3).

To page RAM into low memory, output the first page number to bits 0->4 of
LMPR = 250 dec. Bit 5 should be HIGH if the RAM page is to replace the ROM0
page in section A. Bit 6 should be LOW if the RAM page is to replace the
ROM1 page in section D. (keep bit 7 zero, it controls write-protect in page
A)

So, for example:
OUT 250,33
OUT 251,30

results in:
SECTION A: 0 -> 16383      : PAGE 1
SECTION B: 16384 -> 32767  : PAGE 2
SECTION C: 32768 -> 49151  : PAGE 30
SECTION D: 49152 -> 65535  : PAGE 31

>And where does the screen memory start?

Where do you want it to? There is another port, VMPR = 252, which controls
the screen location and mode. A mode 1 or 2 screen can be located at ANY
page; a mode 3 or 4 screen can be located at any EVEN page.

Bits 0->4 are the start page of the screen bitmap. Bits 5 and 6 control the
mode (ie. subtract 1 from BASIC's mode number, and shift left a few times).
Keep bit 7 zero, it controls MIDI out.

Normally, the screen starts at page 30.

>If I page out
>the ROM can I use the lower 32k for the screen and the higher 32k for
>program . . .

Yes indeed, though I normally do it the other way round to catch mode 1
interrupts.

Note that when you call a machine code routine, it will normally initially
be paged into section C (but not if the routine is in page 0 or 2!). So my
code normally goes something like this:

DUMP 1,0
ORG 32768

in a,(lmpr)
ld (lmprs),a
in a,(hmpr)
ld (hmprs),a
and 31       ;make sure ROM1 is paged out and we're not changing anything else
or 32        ;make sure ROM0 is paged out
out (lmpr),a ;the same memory is paged into sections C and A
jp lmem      ;jump to the copy in section A

hmem:
lmprs: equ $+1
ld a,00      ; restore the previous value as BASIC expects
out (lmpr),a
ret          ; end


ORG $-32768

defs 56-$
interrupt:
ei
ret

lmem:
in a,(vmpr)
ld (vmprs),a
and 31       ; don't fiddle with the MIDI bit
or 96        ; a mode 4 screen
out (hmpr),a

...          ; do some interesting things

vmprs: equ $+1
ld a,00      ; restore BASIC's value in case we changed it
out (vmpr),a
hmprs: equ $+32768
ld a,00      ; put the program back into section C
out (hmpr),a
jp hmem      ; jump there



>and amongst other things neatly dodge the contended memory
>issues? Or is contended memory a whole different prospect on the SAM?

Contended memory is quite a complex issue on the Sam. Basically, ALL
instruction times are rounded up to the nearest 4 t-states, (and execution
speed is approximately halved during the screen area. To get some of the
speed back you can turn the screen off - as I mentioned earlier - but if
you need the display on then basically you're stuck with the contention).
See Based On An Idea issue 2 for a more detailed explanation...

>       Also, I picked up on here that the SAM's video memory is sensibly
>arranged. Can I take it that it therefore that it is a true linear frame
>buffer in the same sense as a VBE2 (or even good old mode 13h) one is? I
>take it one pixel is four bytes?

There are four video modes; MODE 1 is exactly the same as the Spectrum.
Mode 2 is similar, but the bitmap is laid out left to right - top to
bottom. The attribute map starts at an offset of 8192 bytes, and is also
composed of 8pixel wide, single pixel high units, in the same order.

Mode 3 is 512 pixels * 192 lines, where each pixel is 2 bits, laid out left
to right - top to bottom.

Mode 4 is 256 pixels * 192 lines. each pixel is 4 bits, laid out left to
right - top to bottom.

Note that the sixteen colours are an indexed palette, which is changed by
outputting a new value to the CLUT, 248, high byte is the index to change.

Palette values are calculated:
bit value
0   1*B
1   1*R
2   1*G
3   .5*all
4   2*B
5   2*R
6   2*G

>       I'm not really bothered about sound right now, but which port is that
>on?

Select a register by outputting to 511, and send the data to 255. I'm not
going to tell you which register does what, it's far too complicated - look
up the SAA1099 specs or buy a copy of the Sam Technical manual, it'll tell
you everything you need to know.

To be honest, there's not much point doing your own sound, when it is so
much easier to let a package like E-Tracker (or better, ProTracker2) to
play music for you...

Hope that's enough info for you to be getting on with :)

Andrew

--
| Andrew Collier | email [EMAIL PROTECTED]       | Talk sense to a
| Part 2 NatSci  | http://carou.sel.cam.ac.uk/ | fool and he
+----------------+----------------ICQ:38645805-+ calls you foolish
| Selwyn College Student Computer Support Team |   -- Euripides


Reply via email to