-
Notifications
You must be signed in to change notification settings - Fork 1
/
mand65.s
182 lines (152 loc) · 4.29 KB
/
mand65.s
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
.cpu _45gs02
.encoding "petscii_upper"
#import "mega65defs.s"
#import "mega65macros.s"
#import "fixedpt32defs.s"
#import "mandelbrot32defs.s"
#import "vic4fcm_macros.s"
// set to 1 to enable debugging
.eval DEBUG = 0
// some locations need to be defined
.const BASEPAGE = ((>theend)+1) // right after our program
.const VICSTATE = $f0 // basepage storage for old vic state
.const SCREENMEM = (theend & $ff00) + $200 // after basepage
.const GRAPHMEM = $40000 // this is character ram
.const COLORRAM = $ff81000 // this is in high ram $ff 8 0000
/*
* Start of Mandelbrot Explorer 65
*/
Basic65Upstart()
GoFaster()
UnmapMemory()
EnableVIC4()
MoveBasePage(BASEPAGE)
UARTClearKey()
/*
* Initialize Graphics
*/
VIC4_StoreState(VICSTATE)
FCM_InitScreenMemory(0, SCREENMEM, GRAPHMEM, 0, COLORRAM, 1)
FCM_ScreenOn(SCREENMEM, GRAPHMEM, COLORRAM)
lda #0
sta VICIV_BORDERCOL
sta VICIV_SCREENCOL // black back and border
lda #%01010101 // default palette is %11 = 3
sta VICIV_PALETTE // toggle palette to something else
// copy palette
lda #0
sta DMA_ADDRBANK
lda #>dma_copypal
sta DMA_ADDRMSB
lda #<dma_copypal
sta DMA_ADDRLSB_ETRIG // copy commander x16 palette
//
// MANDELBROT
//
jsr mb_init // initialize dr, di
FP_MOV(mand_base_r0, mand_cr) // set cr
lda #0
sta scrn_x
sta scrn_x+1 // x = 0
sta scrn_row
sta scrn_row+1
sta scrn_point
sta scrn_point+1
sta scrn_point+3
lda #[[GRAPHMEM & $ff0000]>>16]
sta scrn_point+2 // scrn_row = $0000, scrn_point = $0004.0000
xloop:
FP_MOV(mand_base_i0, mand_ci) // set ci
lda #200
sta scrn_y // y = 200
yloop:
jsr mb_iter // calculate mandelbrot
.if (DEBUG==1) {
// break at some point to inspect iteration data
lda scrn_x
cmp #150
bne !end+
lda scrn_y
cmp #130
bne !end+
jmp endloop
!end:
}
// draw pixel
//lda scrn_y
lda #128
sec
sbc mand_iter
ldz #0
sta ((scrn_point)),z
FP_DIRECT_ADD(mand_ci,mand_di)
lda #8
clc
adc scrn_point
sta scrn_point
bcc !nov+
inc scrn_point+1 // move point one down the row
!nov: dec scrn_y // dec yloop counter
bne yloop
FP_DIRECT_ADD(mand_cr,mand_dr)
inc scrn_x
bne !nov+
inc scrn_x+1
!nov: lda scrn_x+1
cmp #$01
bne advrow
lda scrn_x
cmp #$40
beq endloop
advrow:
inc scrn_row
lda #7
bit scrn_row
bne smallrow // check if we reached 8
lda #<1592 // one row of characters is 25*64-8 (we already advanced 8...)
clc
adc scrn_row
sta scrn_row
sta scrn_point
lda #>1592
adc scrn_row+1 // add 25*64-8 to scrn_row
sta scrn_row+1
sta scrn_point+1 // and store also in scrn_point(loW)
jmp xloop
smallrow:
lda scrn_row
sta scrn_point
lda scrn_row+1
sta scrn_point+1
jmp xloop
endloop:
#if !BENCHMARK
UARTWaitKey()
#endif
VIC4_RestoreState(VICSTATE)
lda #0
tab // restore base-page to 0
//dec $D019 // this before the cli to clear pending interrupt?
//cli // allow interrupts - BASIC SYS handles this
rts // return
dma_copypal:
.byte $0a, $00 // 11 byte mode
.byte DMA_COPY
.word $300
.word palette
.byte $00
.word VICIII_PALRED
.byte $80 // dma visible(7)
.word $0000
#import "vic4fcm.s"
#import "fixedpt32.s"
#import "mandelbrot32.s"
#import "palette.s"
// Mandeldata:
mand_base:
.byte 48 // 48 iterations
.byte $67, $66, $a6, $fd // rs=-2.35
.byte $00, $00, $40, $01 // re=+1.25
.byte $00, $00, $e0, $fe // is=-1.125
.byte $00, $00, $20, $01 // ie=+1.125
theend: .byte 0