-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathnyan.asm
119 lines (102 loc) · 4.24 KB
/
nyan.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
; Nyan Cat for RC2014 and SC126 with TMS9918 and YM2149
; Hand-written assembly by J.B. Langston
; Nyan Cat images from Passan Kiskat by Dromedaar Vision: http://www.dromedaar.com/
; Nyan Cat theme by Karbofos: https://zxart.ee/eng/authors/k/karbofos/tognyanftro/qid:136394/
; PTx Player by S.V.Bulba <vorobey@mail.khstu.ru>
UseAY: equ 1 ; whether to play music on the AY-3 card
VsyncDiv: equ 3 ; number of vsyncs per Animation frame
org 100h
ld (OldSP),sp ; set up stack
ld sp, Stack
call z180detect ; detect Z180
ld e, 0
jp nz, NoZ180
call z180getclk ; get clock multiple
NoZ180: call TmsSetWait ; set VDP wait loop based on clock multiple
call TmsProbe ; find what port TMS9918A listens on
jp z, NoTms ; abort if not found
call TmsMulticolor ; initialize screen and set background color
ld a, TmsDarkBlue
call TmsBackground
if UseAY
call START
call Timer
ld (LastTimer),a
endif
FirstFrame:
ld hl, Animation ; get address of first frame
NextFrame:
ld (CurrFrame), hl ; save address of next animation frame
SkipDraw:
call keypress ; exit on keypress
jp nz, Exit
if UseAY
call Timer ; see if 50hz timer has changed
ld hl, LastTimer
cp (hl)
ld (hl), a ; save current value for next time
call nz, PLAY ; if changed, play one quark of the song
endif
call TmsRegIn ; only draw when vsyncs counter reaches 0
jp p, SkipDraw
ld hl, VsyncCount
dec (hl)
jp nz, SkipDraw
ld a, VsyncDiv ; reset vsync counter from divisor
ld (hl), a
ld hl, (CurrFrame) ; copy current frame to pattern table
ld de, (TmsPatternAddr)
ld bc, TmsMulticolorPatternLen
call TmsWrite ; leaves hl pointing to next frame
ld de, EndAnimation ; check if hl is past the last frame
or a
sbc hl, de
add hl, de
jp z, FirstFrame ; if so, reset to first frame
jp NextFrame
Exit:
if UseAY
call MUTE
endif
ld sp, (OldSP)
rst 0
NoTmsMessage:
defb "TMS9918A not found, aborting!$"
NoTms: ld de, NoTmsMessage
call strout
jp Exit
if UseAY
LastTimer: defb 0
Timer: ld b, 0f8h ; BIOS SYSGET function
ld c, 0d0h ; TIMER sub-function
rst 8 ; Call BIOS
ld a, l ; MSB to A
ret ; Return to loop
endif
include "tms.asm" ; TMS graphics routines
include "z180.asm" ; Z180 routines
include "utility.asm" ; BDOS utility routines
if UseAY
include "PT3.asm" ; PT3 player
incbin "nyan/nyan.pt3" ; music data
endif
; Change included binary for different cat
Animation:
; change incbin to binary for z88dk
incbin "nyan/nyan.bin" ; The Classic
;incbin "nyan/nyands.bin" ; Skrillex
;incbin "nyan/nyanfi.bin" ; Finland
;incbin "nyan/nyangb.bin" ; Gameboy
;incbin "nyan/nyanlb.bin" ; Netherlands, light background
;incbin "nyan/nyann1.bin" ; Netherlands
;incbin "nyan/nyann2.bin" ; Cheese Cat
;incbin "nyan/nyanus.bin" ; USA
;incbin "nyan/nyanxx.bin" ; Nyanicorn
EndAnimation:
VsyncCount:
defb VsyncDiv ; vsync down counter
CurrFrame:
defw 0 ; pointer to current animation frame
OldSP: defw 0
defs 40h
Stack: