17
17
18
18
OPT -- zxnext=cspect ;DEBUG enable break/exit fake instructions of CSpect (remove for real board)
19
19
20
+ ; ------------------------------------------------------------------------------------
21
+ ; Part 4B - changing magic numbers in source to symbolic constants
22
+ ; ------------------------------------------------------------------------------------
23
+ ; the many EQU directives in the constants file are included here, the EQU does not
24
+ ; emit any machine code byte, just assigns certain symbolic name the numeric value
25
+ ; John is somewhat afraid of them, as the "names" hide the values, and I can agree
26
+ ; on that. So my constants for next registers and ports use suffix with the actual
27
+ ; value, like `ZXN_DMA_P_6B` (port $6B) or `CLIP_LAYER2_NR_18` (NextReg $18).
28
+ INCLUDE "constants.i.asm"
29
+
20
30
STRUCT S_SPRITE_4B_ATTR ; helper structure to work with 4B sprites attributes
21
31
x BYTE 0 ; X0:7
22
32
y BYTE 0 ; Y0:7
@@ -43,26 +53,28 @@ start:
43
53
; disable interrupts, we will avoid using them to keep code simpler to understand
44
54
di
45
55
; make the Layer 2 visible and reset some registers (should be reset by NEXLOAD, but to be safe)
46
- nextreg $ 69 , $ 80 ; Layer 2 visible, ULA bank 5, Timex mode 0
47
- nextreg $ 15 , $ 01 ; LoRes off, layer priority SLU, sprites visible
48
- nextreg $ 12 , 9 ; visible Layer 2 starts at bank 9
49
- nextreg $ 70 , 0 ; 256x192x8 Layer 2 mode, L2 palette offset +0
50
- nextreg $ 16 , 0 ; Layer 2 X,Y offset = [0,0]
51
- nextreg $ 71 , 0 ; including the new NextReg 0x71 for cores 3.0.6+
52
- nextreg $ 17 , 0
56
+ nextreg DISPLAY_CONTROL_NR_69 , $ 80 ; Layer 2 visible, ULA bank 5, Timex mode 0
57
+ nextreg SPRITE_CONTROL_NR_15 , $ 01 ; LoRes off, layer priority SLU, sprites visible
58
+ nextreg LAYER2_RAM_BANK_NR_12 , 9 ; visible Layer 2 starts at bank 9
59
+ nextreg LAYER2_CONTROL_NR_70 , 0 ; 256x192x8 Layer 2 mode, L2 palette offset +0
60
+ nextreg LAYER2_XOFFSET_NR_16 , 0 ; Layer 2 X,Y offset = [0,0]
61
+ nextreg LAYER2_XOFFSET_MSB_NR_71 , 0 ; including the new NextReg 0x71 for cores 3.0.6+
62
+ nextreg LAYER2_YOFFSET_NR_17 , 0
53
63
54
64
; setup Layer 2 palette - map palette data to $E000 region, to process them
55
- nextreg $ 57 , $$ BackGroundPalette ; map the memory with palette to the $E000..$FFFF
65
+ nextreg MMU7_E000_NR_57 , $$ BackGroundPalette ; map the memory with palette
56
66
; the "$$" is special operator of sjasmplus to get memory page of particular
57
67
; label (the 8kiB memory page)
58
- nextreg $ 43 , %0 '001' 0 '0' 0 ' 0 ; write to Layer 2 palette, select first palettes
59
- nextreg $ 40 , 0 ; color index
60
- ld b , 0 ; 256 colors (loop counter)
61
- ld hl , BackGroundPalette ; address of first byte of 256x 24 bit color def.
68
+ nextreg PALETTE_CONTROL_NR_43 , %0 '001' 0 '0' 0 ' 0 ; write to Layer 2 palette, select first palettes
69
+ nextreg PALETTE_INDEX_NR_40 , 0 ; color index
70
+ ld b , 0 ; 256 colors (loop counter)
71
+ ld hl , BackGroundPalette ; address of first byte of 256x 24 bit color def.
62
72
; calculate 9bit color from 24bit value for every color
63
73
; -> will produce pair of bytes -> write that to nextreg $44
64
74
SetPaletteLoop:
65
75
; TGA palette data are three bytes per color, [B,G,R] order in memory
76
+ ; so palette data are: BBBbbbbb GGGggggg RRRrrrrr
77
+ ; (B/G/R = 3 bits for Next, b/g/r = 5bits too fine for Next, thrown away)
66
78
; first byte to calculate: RRR'GGG'BB
67
79
ld a , (hl) ; Blue
68
80
inc hl
@@ -83,12 +95,12 @@ SetPaletteLoop:
83
95
and % 111 '000' 00 ; top three red bits
84
96
or d ; add green bits
85
97
or e ; add blue bits
86
- nextreg $ 44 , a ; RRR'GGG'BB
98
+ nextreg PALETTE_VALUE_9BIT_NR_44 , a ; RRR'GGG'BB
87
99
; second byte is: p000'000B (priority will be 0 in this app)
88
100
xor a
89
101
rl c ; move top bit from C to bottom bit in A (Blue third bit)
90
102
rla
91
- nextreg $ 44 , a ; p000'000B p=0 in this image always
103
+ nextreg PALETTE_VALUE_9BIT_NR_44 , a ; p000'000B p=0 in this image always
92
104
djnz SetPaletteLoop
93
105
94
106
; the image pixel data are already in the correct banks 9,10,11 - loaded by NEX loader
@@ -105,14 +117,14 @@ SetPaletteLoop:
105
117
106
118
; upload the sprite gfx patterns to patterns memory (from regular memory - loaded by NEX loader)
107
119
; preconfigure the Next for uploading patterns from slot 0
108
- ld bc , $ 303B
120
+ ld bc , SPRITE_STATUS_SLOT_SELECT_P_303B
109
121
xor a
110
122
out (c) , a ; select slot 0 for patterns (selects also index 0 for attributes)
111
123
; we will map full 16kiB to memory region $C000..$FFFF (to pages 25,26 with sprite pixels)
112
- nextreg $ 56 , $$ SpritePixelData ; C000..DFFF <- 8k page 25
113
- nextreg $ 57 , $$ SpritePixelData + 1 ; E000..FFFF <- 8k page 26
124
+ nextreg MMU6_C000_NR_56 , $$ SpritePixelData ; C000..DFFF <- 8k page 25
125
+ nextreg MMU7_E000_NR_57 , $$ SpritePixelData + 1 ; E000..FFFF <- 8k page 26
114
126
ld hl , SpritePixelData ; HL = $C000 (beginning of the sprite pixels)
115
- ld bc , $ 5B ; sprite pattern-upload I/O port, B=0 (inner loop counter)
127
+ ld bc , SPRITE_PATTERN_P_5B ; sprite pattern-upload I/O port, B=0 (inner loop counter)
116
128
ld a , 64 ; 64 patterns (outer loop counter), each pattern is 256 bytes long
117
129
UploadSpritePatternsLoop:
118
130
; upload 256 bytes of pattern data (otir increments HL and decrements B until zero)
@@ -169,11 +181,11 @@ GameLoop:
169
181
call WaitForScanlineUnderUla
170
182
; upload sprite data from memory array to the actual HW sprite engine
171
183
; reset sprite index for upload
172
- ld bc , $ 303B
184
+ ld bc , SPRITE_STATUS_SLOT_SELECT_P_303B
173
185
xor a
174
186
out (c) , a ; select slot 0 for sprite attributes
175
187
ld hl , Sprites
176
- ld bc , $ 57 ; B = 0 (repeat 256x), C = sprite pattern-upload I/O port
188
+ ld bc , SPRITE_ATTRIBUTE_P_57 ; B = 0 (repeat 256x), C = sprite pattern-upload I/O port
177
189
; out 512 bytes in total (whole sprites buffer)
178
190
otir
179
191
otir
@@ -248,10 +260,10 @@ WaitForScanlineUnderUla:
248
260
ld (TotalFrames + 2 ) , hl
249
261
.totalFramesUpdated:
250
262
; read NextReg $1F - LSB of current raster line
251
- ld bc , $ 243B
252
- ld a , $ 1F
263
+ ld bc , TBBLUE_REGISTER_SELECT_P_243B
264
+ ld a , RASTER_LINE_LSB_NR_1F
253
265
out (c) , a ; select NextReg $1F
254
- inc b
266
+ inc b ; BC = TBBLUE_REGISTER_ACCESS_P_253B
255
267
; if already at scanline 192, then wait extra whole frame (for super-fast game loops)
256
268
.cantStartAt192:
257
269
in a , (c) ; read the raster line LSB
0 commit comments