Programming - a quick procedure for printing sprites via a stack from WoodlandStudio.

Deja Vu #0A
__________________________________________

(C) Nathan/Woodland Studio
__________________________________________

              Hello!

   Writes to you Natan aka Andrey A. Timofeev
from WoodlandStudio,that in the glorious city
Lesosibirsk on the banks of the great Yeni-river
this one I would like to present to your attention my
the first (I hope not the last) small
Shuy note.
   So let's begin. It's no secret that
the fastest screen output is carried out by -
via the stack. I will only consider a quick one
sprite printing.

  Here's a typical example:

in SP - sprite data address,
in HL - address on the screen,
 ld sp,SpriteAddress
 ld hl,ScreenAddress

 pop de  ; collected data in MASK, DATA format
 ld a,(hl) ; took a byte from the screen
 and d  ; put on a mask
 or e  ; and data
 ld (hl),a ; placed on the screen

       and so on.

   Maybe you remember something else. General
The recognized disadvantage of such procedures is
it becomes impossible for them to work when resolved
heavy interruptions. I'll explain why - then
mu that ends in "y". But seriously,
then the following happens. At the moment of arrival
interrupts the processor places on the ad stack
return res from ISR (Interrup Service
Routine), and the stack currently indicates
on the sprite data, as a result the latest
are destroyed, the sprite is in trouble. Usually in such
In cases of interruption, interruptions are simply prohibited. But
what to do if, for example, on interruptions
hanging music player. In ZX-Format'e
8, in the article "epic" there are two solutions
solutions to this problem:

   1. Keep 2 copies of each in memory
sprite or create a copy of the sprite before
print it through the stack. As you understand
this method is not rational in any way
speed, nor in terms of performance.

   2. Author of this technique V. Mednonogov.
He used this technique in a cool and
steering toy "Black Raven"  (everything is there
sprites are printed via the stack). Since
the author himself (according to my data) allowed
free distribution and use
games, then, as they say, you will get it. Below
the beginning of the processing procedure is shown
interruptions from the game CV. In order to
to use this code you should consider
the following points:
  a) the interrupt handling procedure must
have your own stack - StackIM2;
  b) you can only read data from the stack
register pair DE.

   Well, that's all for today, look,
figure it out. God help us and Spectrum
hands...

ISR   ex de,hl ; start of interrupt handling procedure
 ; put this exact address in
 ; interrupt vector
 ex (sp),hl ; we will recover damaged data
 ld (SaveRET+1),hl ; save the return address from ISR
ex de,hl
 pop de
 ld (SaveSP+1),sp ; save the program stack
 ld sp,StackIM2 ; let's reinstall the stack
 call mainISR ; calling the main IM2 handler
SaveSP  ld sp,0
 ei ; let's resolve interrupts as they were
 ; automatically prohibited
SaveRET jp 0

mainISR push all registers
        ...
        pop all registers
        ret

       I want to share with you one useful
new procedure. At one time, while doing pro-
programming VG-93, I encountered
Problem reading the status register (#1f).
As a result of the search, I found as many as three solutions
of this task(from Larchenko and Rodionova, in
ZX-Review  - using interrupts, at Roshchi-
on),but none of them satisfied me
Rilo. Then I began detailed research
ROM TR-DOS. As a result, this is what
beamed:

; reading the VG-93 status register
; no input data
; output: a - contents of the status register
; output interrupts are enabled,
; but you can also ban it
in_1f
  di
 ld a,(Trk)
 ld d,a
 ld a,(#5cc2)
 ld (_5cc2),a
 ld a,(#5ccd)
 ld (_5ccd),a
 ld hl,(#5cc3)
 ld (_5cc3),hl
 ld hl,(#5d02)
      ld (_5d02),hl
      ld hl,(#5d04)
      ld (_5d04),hl
      ld hl,#2740
      jp dos
ret
      pop hl
      pop hl
      pop hl
      pop hl
      pop hl
      pop hl
      ld a,(#5ccd)
      push af
      ld a,(_5cc2)
      ld (#5cc2),a
      ld a,(_5ccd)
      ld (#5ccd),a
      ld hl,(_5cc3)
      ld (#5cc3),hl
      ld hl,(_5d02)
      ld (#5d02),hl
      ld hl,(_5d04)
      ld (#5d04),hl
      pop af
      ei
      ret
dos
      push hl
      jp #3d2f
_5ccd db 0
_5cc2 db 0
_5cc3 dw 0
_5d02 dw 0
_5d04 dw 0

Trk   db 0 ; текущая дорожка

   А теперь, для лучшего понимания вышена-
писанного, приведу фрагмент из ПЗУ ТР-ДОС:

#2740
      in a,(#1f)
      ld (#5ccd),a
      ld e,d
      push de
      ld a,e
      out (#7f),a
      ld a,#18
      call #3d9a
      . . . . . .
#3d9a
      out (#1f),a
      push hl
      rst #20
      dw #1f54
      . . . . . .
#0020
      jp #2f72
      . . . . . .
#2f72
      ld (#5d02),hl
      ld (#5d04),de
      pop hl
      ld e,(hl)
      inc hl
      ld d,(hl)
      inc hl
      push hl
      ld hl,#3d2f
      push hl
      push de
      ld hl,#5cc2
      push hl
      ld hl,(#5d02)
      ld de,(#5d04)
      ret

   Для  предотвращения недоразумений сооб-
щаю, что  у  меня ZS-Scorpion 256 Turbo+ с
ПрофПЗУ версии 3 с чем-то.

Андрей А. Тимофеев aka Natan from Woodland
Studio
mailto: ws_mason@mail.ru
------------------------------------------

Share your thoughts about the article