-----Oorspronkelijk bericht-----
Van: Maarten ter Huurne <[EMAIL PROTECTED]>
Aan: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Datum: zondag 21 juni 1998 3:37
Onderwerp: Re: Problems with assembler
:At 12:42 AM 06/21/98 +0200, you wrote:
:
:>I want to write data to the Pattern Table of Screen 2. Doing it from BASIC
:>with VPOKE and VPEEK works good, but in assembler not. I've write this
:>little program:
:>
:>START: EQU &HA000 ; Start address
:>SCREEN2: EQU &H72 ; SCREEN 2 BIOS routine
:>VPOKE: EQU &H4D ; VPOKE BIOS routine
:>PAT2: EQU &H0000 ; SCREEN 2 Pattern Table Address
:>COL2: EQU &H2000 ; SCREEN 2 Color Table Address
:>NOM2: EQU &H1800 ; SCREEN 2 Name Table Address
:>NUMCHAR: EQU 4 ; Number of chars to redefine
:>
:> ORG START
:> CALL SCREEN2
:> LD HL, PAT2
:> LD B, NUMCHAR*8-1
:> LD DE, DEFCHAR
:>LOOP: LD A, (DE)
:> CALL VPOKE
:> INC HL
:> INC DE
:> DJNZ LOOP
:> LD A,(DE)
:> CALL VPOKE
:> RET
:>
:>
:>DEFCHAR: DB *** Data of the new chars ***
:
:Why don't you simply go through the loop NUMCHAR*8 times? You gain very
:little speed by doing the last VPOKE outside the loop. Besides, when your
:assembly programs become larger, the size of your code is as important as
:the speed, believe me.
Also, if you do that, bugs are way easier to discover.
:>Its function is to redefine NUMCHAR characters, that is, to write
NUMCHAR*8
:>bytes in the Pattern Table of SCREEN 2.
:>But... this doesn't work.
:>What is wrong?
I don't know, but maybe it's a good idea to write your own routines?
You can first call the Bios-routine SETWRT to set the VRAM-adress and then
just write to the VDP-port specified by #0007 in the Bios (usually #98, you
don't really have to test for it).
So, oficially, you'll have to do it like this:
ld hl,#2000
call SETWRT
ld a,(#0007)
ld c,a
out (c),value or any register exept F.
By the way, if you want to write to the next adress, you don't have to
adjust the VDPWRT-adress again, but you can just add another "OUT (c),value
or any register exept F".
But, you can also do it like this, for this is more clear and uses less
registers. The loss of speed is not important since if you use the faster
way you'll have to wait for the VDP with a nop. Anyway, it gives the same
result on every MSX (exept for some MSX1's upgraded to an MSX2 with a
certain cartridge, but no-one uses them).
Like this:
ld hl,#2000
call SETWRT
ld a,value
out (#98),a or another register
You can also put SETWRT in your own code, the routine (faster than the Bios)
is:
;Input: HL
;
Set_Vdp_Write:
ld a,l
di
out (#99),a
ld a,h
and %00111111
or 64
ei
out (#99),a
ret
And here is SETRD too:
;Input: HL
;
Set_Vdp_Read:
ld a,l
di
out (#99),a
ld a,h
and %00111111
ei
out (#99),a
ret
Now you can put a byte on adress #2000 like this:
ld hl,#2000
call Set_Vdp_Write
ld a,value
out (#98),a or another register
By the way, there are other write-and read-routines for the MSX2, for the
MSX1-videochip can handle only 16k of VRAM, while the MSX2 can handle up to
128k of (normal) VRAM. Therefor, on the MSX2, the VRAM has to be adressed
using 3 registers; HL for the lower part (bits 0-15, 64k), and A for the
high part (bit 16, 128k)
So, here are the equalivents of NSETRD and NSETWR (well, not the same
registers, but what the... These are faster.)
;Input: AHL
;
Set_Vdp_Write:
rlc h
rla
rlc h
rla
srl h
srl h
di
out (#99),a
ld a,14+128
out (#99),a
ld a,l
nop
out (#99),a
ld a,h
or 64
ei
out (#99),a
ret
;Input: AHL
;
Set_Vdp_Read:
rlc h
rla
rlc h
rla
srl h
srl h
di
out (#99),a
ld a,14+128
out (#99),a
ld a,l
nop
out (#99),a
ld a,h
ei
out (#99),a
ret
Writing to VRAM using them has to be done like this:
Example, to page 3 of sreen 5 (adress #18000)
ld a,1
ld hl,#8000
call Set_Vdp_Write
ld a,value
out (#98),a or another register
Oh, and I forgot, how to read:
>From adress #4000 in page 1 of screen 5:
xor a
ld hl,#4000
call Set_Vdp_Read
in (#98),any register
Well, I hope to have helped you on your way to become a very good (and
famous!) programmer. CA!
~Grauw
****
MSX Mailinglist. To unsubscribe, send an email to [EMAIL PROTECTED] and put
in the body (not subject) "unsubscribe msx [EMAIL PROTECTED]" (without the
quotes :-) Problems? contact [EMAIL PROTECTED] (www.stack.nl/~wiebe/mailinglist/)
****