Created
November 5, 2016 09:38
-
-
Save vladkorotnev/eb82cf170b02b95e4f6f6ec343bb91d8 to your computer and use it in GitHub Desktop.
Fade in and out for ZX Spectrum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Example code for Fade-In and Fade-Out | |
DEVICE ZXSPECTRUM128 | |
ORG 40000 | |
INCBIN "my_picture.scr" | |
ORG 30000 | |
TEST | |
EI | |
CALL CLR_ATTR | |
; Set to image origin and prepare the fade in | |
LD HL,40000 | |
CALL APPEAR_INIT | |
; Perform ALOOP 7 times for 7 bits of attributes (we don't use FLASH color here) | |
LD B,7 | |
ALOOP | |
; Preserve counter | |
LD HL,(iterator) | |
LD (HL),B | |
; Set to image attr origin and do step | |
LD HL,46144 | |
CALL APPEAR_STEP | |
; Wait 2 frames | |
LD B,2 | |
CALL WAIT | |
; Restore iterator | |
LD HL,(iterator) | |
LD B,(HL) | |
DJNZ ALOOP | |
; Wait ~1s before going to fade out | |
LD B,50 | |
CALL WAIT | |
; Prepare the fade out | |
CALL DISAPPEAR_INIT | |
; 7 times BLOOP for 7 bits again | |
LD B,7 | |
BLOOP | |
; Preserve counter | |
LD HL,(iterator) | |
LD (HL),B | |
; Do step | |
CALL DISAPPEAR_STEP | |
; Wait 2 frames | |
LD B,2 | |
CALL WAIT | |
; Restore iterator | |
LD HL,(iterator) | |
LD B,(HL) | |
DJNZ BLOOP | |
; Wait ~1s before going to fade in | |
LD B,50 | |
CALL WAIT | |
; Repeat forever | |
JP TEST | |
; A procedure for waiting | |
WAIT: ; -- B must be number of frames | |
HALT | |
DJNZ WAIT | |
RET | |
iterator defb 0 ; to preserve the loop counter | |
INCLUDE "genscreen.asm" ; Load the generic screen operations | |
INCLUDE "fx.fadein.asm" ; Load the fade in | |
INCLUDE "fx.fadeout.asm" ; Fade out | |
SAVESNA "fade.test.sna",TEST |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ------------------------------------------------------------------ | |
APPEAR_INIT ; HL -- must point to image area start | |
LD DE,SCREEN_AREA ; Video buffer | |
LD BC,SCREEN_SZ ; Only data | |
LDIR ; Copy area | |
LD A,0 ; Reset mask to 0 | |
LD (APPEAR_MSK),A | |
RET | |
; ------------------------------------------------------------------- | |
APPEAR_STEP ; HL -- must point to attr area of original | |
LD A,(APPEAR_MSK) ; Current color mask | |
RLA ; Shift mask left | |
SET 0,A ; Set 1st bit of mask again | |
BIT 7,A ; Check if we are reaching FLASH | |
JR NZ, _APP_DONE ; If FLASH, abandon the thing because all colors are in place now | |
LD (APPEAR_MSK),A ; Save mask for next step | |
LD DE,ATTR_AREA ; Beginning of screen color memory | |
LD B,255 ; pass of 255 items | |
_APP_LOOP1 LD A,(APPEAR_MSK) ; Copy mask to accumulator | |
LD C,(HL) ; Copy current byte of original | |
AND C ; Bitwise and of mask and original | |
; Now A contains the resulting attribute | |
LD (DE),A ; Write it to the screen | |
INC HL | |
INC DE | |
DJNZ _APP_LOOP1 | |
LD B,255 ; pass of 255 items | |
_APP_LOOP2 LD A,(APPEAR_MSK) ; Copy mask to accumulator | |
LD C,(HL) ; Copy current byte of original | |
AND C ; Bitwise and of mask and original | |
; Now A contains the resulting attribute | |
LD (DE),A ; Write it to the screen | |
INC HL | |
INC DE | |
DJNZ _APP_LOOP2 | |
LD B,255 ; pass of 255 items | |
_APP_LOOP3 LD A,(APPEAR_MSK) ; Copy mask to accumulator | |
LD C,(HL) ; Copy current byte of original | |
AND C ; Bitwise and of mask and original | |
; Now A contains the resulting attribute | |
LD (DE),A ; Write it to the screen | |
INC HL | |
INC DE | |
DJNZ _APP_LOOP3 | |
LD B,3 ; pass of 255 items | |
_APP_LOOP4 LD A,(APPEAR_MSK) ; Copy mask to accumulator | |
LD C,(HL) ; Copy current byte of original | |
AND C ; Bitwise and of mask and original | |
; Now A contains the resulting attribute | |
LD (DE),A ; Write it to the screen | |
INC HL | |
INC DE | |
DJNZ _APP_LOOP4 | |
_APP_DONE RET | |
; ------------------------------------------------------------------- | |
APPEAR_MSK db 0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ------------------------------------------------------------------ | |
DISAPPEAR_INIT | |
LD A,127 ; Reset mask to all on | |
LD (DISAPPEAR_MSK),A | |
RET | |
; ------------------------------------------------------------------- | |
DISAPPEAR_STEP | |
LD A,(DISAPPEAR_MSK) ; Current color mask | |
OR A ; Clear carry | |
RRA ; Shift mask right | |
LD (DISAPPEAR_MSK),A ; Save mask for next step | |
LD HL,ATTR_AREA ; Beginning of screen color memory | |
LD B,255 ; pass of 255 items | |
_DISAP_L1 LD A,(DISAPPEAR_MSK) ; Copy mask to accumulator | |
LD C,(HL) ; Copy current byte of original | |
AND C ; Bitwise and of mask and original | |
; Now A contains the resulting attribute | |
LD (HL),A ; Write it to the screen | |
INC HL | |
DJNZ _DISAP_L1 | |
LD B,255 ; pass of 255 items | |
_DISAP_L2 LD A,(DISAPPEAR_MSK) ; Copy mask to accumulator | |
LD C,(HL) ; Copy current byte of original | |
AND C ; Bitwise and of mask and original | |
; Now A contains the resulting attribute | |
LD (HL),A ; Write it to the screen | |
INC HL | |
DJNZ _DISAP_L2 | |
LD B,255 ; pass of 255 items | |
_DISAP_L3 LD A,(DISAPPEAR_MSK) ; Copy mask to accumulator | |
LD C,(HL) ; Copy current byte of original | |
AND C ; Bitwise and of mask and original | |
; Now A contains the resulting attribute | |
LD (HL),A ; Write it to the screen | |
INC HL | |
DJNZ _DISAP_L3 | |
LD B,3 ; pass of 255 items | |
_DISAP_L4 LD A,(DISAPPEAR_MSK) ; Copy mask to accumulator | |
LD C,(HL) ; Copy current byte of original | |
AND C ; Bitwise and of mask and original | |
; Now A contains the resulting attribute | |
LD (HL),A ; Write it to the screen | |
INC HL | |
DJNZ _DISAP_L4 | |
_DISAP_DONE RET | |
; ------------------------------------------------------------------- | |
DISAPPEAR_MSK db 0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEFINE ATTR_AREA 22528 | |
DEFINE ATTR_SZ 767 | |
DEFINE SCREEN_AREA 16384 | |
DEFINE SCREEN_SZ 6144 | |
; ------------------------------------------------------------------- | |
CLR_ATTR | |
LD HL,ATTR_AREA | |
LD A,0 | |
LD B,255 | |
CLLP1 LD (HL),A ; Copy 0 to screen color area | |
INC HL | |
DJNZ CLLP1 | |
LD B,255 | |
CLLP2 LD (HL),A ; Copy 0 to screen color area | |
INC HL | |
DJNZ CLLP2 | |
LD B,255 | |
CLLP3 LD (HL),A ; Copy 0 to screen color area | |
INC HL | |
DJNZ CLLP3 | |
LD B,3 | |
CLLP4 LD (HL),A ; Copy 0 to screen color area | |
INC HL | |
DJNZ CLLP4 | |
RET | |
; ------------------------------------------------------------------- | |
CLS CALL #0D6B | |
RET | |
; ------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment