• R/O
  • SSH
  • HTTPS

oricsdk: Commit


Commit MetaInfo

Revision1541 (tree)
Time2020-10-19 03:10:30
Authordbug

Log Message

Source code that accompanies the blog post about distorting pictures on the Atari STe
This compiles with RMAC and pictures are converted with PictConv

Associated video: https://www.youtube.com/watch?v=zYt3tTdsCYU
Associated article: http://blog.defence-force.org

Change Summary

Incremental Difference

--- public/atari/tutorials/SineWave/SineWave.s (nonexistent)
+++ public/atari/tutorials/SineWave/SineWave.s (revision 1541)
@@ -0,0 +1,344 @@
1+;
2+; Horizontal Sine Shifting
3+; on the Atari STE
4+;
5+; Inspired by the blog article from Mark Wrobel who explained how to do it
6+; on the Amiga using the Copper, and apparently people on Twitter were interested
7+; to know how I did that in my old Atari STe demos, so there it is.
8+;
9+; The original blog post is https://www.markwrobel.dk/post/amiga-machine-code-letter12-wave/
10+; Twitter thread: https://twitter.com/mark_wrobel/status/1316338201452257280
11+;
12+; System requirements: Half meg Atari STE or Mega STe
13+;
14+
15+ .macro pause delay
16+ dcb.w \delay,$4e71
17+ .endm
18+
19+ .text
20+
21+ProgStart:
22+ ; Call the main routine in supervisor mode
23+ move.l #SupervisorMain,-(sp)
24+ move.w #$26,-(sp)
25+ trap #14
26+ addq.w #6,sp
27+
28+ ; Quit
29+ clr.w -(sp)
30+ trap #1
31+
32+
33+SupervisorMain:
34+ ; We need to start by clearing the BSS in case of some packer let some crap
35+ ; (This has to be done first, else we will lose data)
36+ lea bss_start,a0
37+ lea bss_end,a1
38+ moveq #0,d0
39+.loop_clear_bss:
40+ move.l d0,(a0)+
41+ cmp.l a1,a0
42+ ble.s .loop_clear_bss
43+
44+ ;
45+ ; We need to know on which machine we are running the intro.
46+ ; We accept STE and MegaSTE as valid machines.
47+ ; Anything else will have a nice message telling them to "upgrade" or use an emulator :)
48+ ;
49+ bsr DetectMachine
50+ tst d0
51+ bne.s setup_system
52+
53+ ; This machine is not a STE/MSTE, print a message and quit
54+ pea NotASteMessage
55+ move #9,-(sp)
56+ trap #1
57+ addq #6,sp
58+
59+ ; wait key
60+ move #7,-(sp)
61+ trap #1
62+ addq #2,sp
63+ rts
64+
65+NotASteMessage: dc.b "This demo works only on STE or MegaSTE",0
66+ .even
67+
68+ ;
69+ ; Setup: Save all the system parameters we are going to modify
70+ ;
71+setup_system:
72+ move.w #$2700,sr
73+ bsr KeyboardFlushBuffer
74+
75+ move.b $fffffa07.w,save_iera
76+ sf $fffffa07.w ; Disable iera
77+ move.b $fffffa09.w,save_ierb
78+ sf $fffffa09.w ; Disable ierb
79+
80+ move.b $ffff820a.w,save_freq
81+ move.b $ffff8260.w,save_rez
82+ move.b #0,$ffff8260.w ; Force to 320x200x16 graphic mode
83+ move.b $ffff8265.w,save_pixl
84+
85+ move.b $ffff8201.w,save_screen_addr_1 ; Screen base pointeur (STF/E)
86+ move.b $ffff8203.w,save_screen_addr_2 ; Screen base pointeur (STF/E)
87+ move.b $ffff820d.w,save_vbaselo ; Save low byte (STE only)
88+
89+ move.l #empty_line+256,d0 ; Change the screen address to point on some empty data
90+ lsr.l #8,d0
91+ move.b d0,$ffff8203.w ; STF - Screen base adress (mid byte)
92+ lsr.w #8,d0
93+ move.b d0,$ffff8201.w ; STF - Screen base adress (high byte)
94+ move.b #0,$ffff820d.w ; STE - Screen base adress (low byte)
95+
96+ move.b $ffff820f.w,save_linewidth
97+
98+ movem.l $ffff8240.w,d0-d7 ; STF/STE Palette
99+ movem.l d0-d7,save_palette
100+ movem.l king_tut_picture,d0-d7 ; Replace the palette with our picture's
101+ movem.l d0-d7,$ffff8240.w
102+
103+ move.l $70.w,save_70 ; VBL
104+ move.l #FullTimerVbl,$70.w
105+
106+ tst.b machine_is_megaste
107+ beq.s .end_megaste
108+.megaste:
109+ move.b $ffff8e21.w,save_mste_cache
110+ move.b #%00,$ffff8e21.w ; 8mhz without cache
111+.end_megaste:
112+ move.w #$2300,sr
113+
114+demo_loop:
115+ ; Wait a bit and then quit
116+ move #50*300,d0
117+.wait_loop:
118+
119+ ; Synchronize with the VBL
120+ sf flag_vbl
121+.waive_vbl_loop:
122+ tst.b flag_vbl
123+ beq.s .waive_vbl_loop
124+ sf flag_vbl
125+
126+ ; Test the keyboard
127+ btst #0,$fffffc00.w ; Is a key pressed?
128+ beq.s .no_key_pressed
129+ cmp.b #$39,$fffffc02.w ; $39 is the key code for the SPACE bar
130+ beq.s .exit_loop
131+.no_key_pressed:
132+ dbra d0,.wait_loop
133+.exit_loop:
134+
135+ ; Restore all the system parameters we saved earlier
136+restore_system:
137+ move.w #$2700,sr
138+ bsr KeyboardFlushBuffer
139+ move.b save_iera,$fffffa07.w
140+ move.b save_ierb,$fffffa09.w
141+
142+ move.b save_freq,$ffff820a.w
143+ move.b save_rez,$ffff8260.w
144+ move.b save_pixl,$ffff8265.w
145+
146+ move.b save_screen_addr_1,$ffff8201.w
147+ move.b save_screen_addr_2,$ffff8203.w
148+ move.b save_vbaselo,$ffff820d.w
149+
150+ move.b save_linewidth,$ffff820f.w
151+
152+ movem.l save_palette,d0-d7
153+ movem.l d0-d7,$ffff8240.w
154+
155+ move.l save_70,$70.w
156+
157+ ;
158+ ; System specific load
159+ ;
160+ tst.b machine_is_megaste
161+ beq.s .end_megaste
162+.megaste:
163+ move.b save_mste_cache,$ffff8e21.w
164+.end_megaste:
165+ move.w #$2300,sr
166+ rts
167+
168+
169+; 0-200
170+; 245/7 for 50hz interrupt (7=prediv 200)
171+; 150/5 for normal screen sync
172+; 99/4 for top border (4=prediv 50)
173+FullTimerVbl:
174+ movem.l d0-a6,-(sp)
175+
176+ st flag_vbl
177+
178+ ; Move stuff around
179+ move.w king_tut_sinus_offset,d3
180+ add.w #2,d3
181+ move.w d3,king_tut_sinus_offset
182+
183+ move.l #empty_line+32,d4
184+ lsl.l #8,d4
185+
186+ move.l #king_tut_picture+32,d5
187+ lsl.l #8,d5
188+ move.l #208<<8,d6 ; 12/3
189+
190+ lea $ffff8260.w,a0 ; 8/2 resolution
191+ lea $ffff820a.w,a1 ; 8/2 frequence
192+ lea sine_255,a2
193+
194+ .opt "~oall"
195+
196+ ; STE hardware compatible synchronization code
197+synchronize:
198+ move.b #0,$ffff8209.w
199+ moveq #16,d2
200+.wait_sync:
201+ move.b $ffff8209.w,d0
202+ beq.s .wait_sync
203+ sub.b d0,d2
204+ lsl.b d2,d0
205+
206+synchronization_done:
207+ pause 85
208+
209+ move.w #199-1,d7 ; 8/2
210+king_tut_picture_loop:
211+ movep.l d4,-5(a1) ; 24/6 - SCREEN ADDRESS ($ffff8205/07/09/0B)
212+ move.b d4,91(a1) ; 12/3 - PIXEL SHIFT ($ffff8265)
213+
214+ move.w a0,(a0) ; 8/2 - LEFT BORDER OPENING
215+ move.b d0,(a0) ; 8/2 - LEFT BORDER OPENING
216+
217+ pause 62
218+ moveq.l #0,d1 ; 1
219+ moveq.l #0,d2 ; 1
220+ and.w #510,d3 ; 2
221+ move.w (a2,d3),d1 ; 4
222+ addq.w #2,d3 ; 1
223+
224+ move.l d5,d4 ; 1
225+
226+ move.w d1,d2 ; 1
227+ and.w #15,d1 ; 2
228+ move.b d1,d4 ; 1 Pixel shift
229+
230+ lsr #4,d2 ; 4
231+ lsl #3,d2 ; 3
232+ lsl #8,d2 ; 6
233+ add.l d2,d4 ; 2 Final offset
234+
235+ move.b d0,(a1) ; 8/2 - RIGHT BORDER OPENING
236+ move.w a0,(a1) ; 8/2 - RIGHT BORDER OPENING
237+
238+ add.l d6,d5 ; 2
239+ pause 15
240+ dbra d7,king_tut_picture_loop ; 12/3 taken, 16/4 not-taken
241+
242+ .opt "+o"
243+
244+ sf.b $ffff8265.w ; End of Screen stabilizer (reset the pixel offset)
245+
246+ movem.l (sp)+,d0-a6
247+ rte
248+
249+
250+
251+;
252+; The Cookie Jar can be used to detect the type of machine.
253+; This feature was first implemented on the STE.
254+; So if the Cookie Jar is missing we can safely assume we are running on a STF machine.
255+;
256+; http://leonard.oxg.free.fr/articles/multi_atari/multi_atari.html
257+;
258+DetectMachine:
259+ sf machine_is_ste
260+ sf machine_is_megaste
261+
262+ move.l $5a0.w,d0
263+ bne.s .found_cookie
264+ ; No cookie, this is a ST
265+.detection_refused:
266+ moveq #0,d0
267+ rts
268+
269+.found_cookie:
270+ ; We found a cookie pointer, this is not a ST for sure
271+ move.l d0,a0
272+.loop_cookie:
273+ move.l (a0)+,d0 ; Cookie descriptor
274+ beq.s .detection_refused
275+ move.l (a0)+,d1 ; Cookie value
276+
277+ cmp.l #"CT60",d0
278+ beq.s .detection_refused ; We do not run on Falcon, accelerated or not
279+ cmp.l #"_MCH",d0
280+ bne.s .loop_cookie
281+
282+.found_machine:
283+ cmp.l #$00010000,d1
284+ beq.s .found_ste
285+ cmp.l #$00010010,d1
286+ beq.s .found_mste
287+ bra.s .detection_refused ; We do not run on TT
288+
289+.found_mste:
290+ st machine_is_megaste
291+.found_ste:
292+ st machine_is_ste
293+.found_st:
294+ moveq #-1,d0
295+ rts
296+
297+
298+KeyboardFlushBuffer:
299+ btst.b #0,$fffffc00.w ; Have we some keys to wait for ?
300+ beq.s .exit
301+ tst.b $fffffc02.w
302+ bra.s KeyboardFlushBuffer
303+.exit:
304+ rts
305+
306+
307+ .data
308+
309+king_tut_picture: incbin "exported\\tutankhamun.pi1" ; 32 bytes of palette, then 200 lines of 408 pixels (overscan)
310+sine_255: incbin "exported\\sine_255.bin" ; 16 bits, unsigned between 00 and 127
311+
312+ .bss
313+
314+bss_start:
315+ .even
316+
317+save_70: ds.l 1 ; VBL handler
318+save_palette: ds.w 16
319+
320+king_tut_sinus_offset: ds.w 1 ; Position in the sinus table
321+
322+empty_line: ds.b 256+230 ; Some empty bytes to have something "clean" to display during the sync line
323+
324+machine_is_ste: ds.b 1
325+machine_is_megaste: ds.b 1
326+save_mste_cache: ds.b 1
327+
328+save_iera: ds.b 1 ; Interrupt enable register A
329+save_ierb: ds.b 1 ; Interrupt enable register B
330+
331+save_freq: ds.b 1
332+save_rez: ds.b 1
333+save_pixl: ds.b 1
334+
335+save_screen_addr_1: ds.b 1
336+save_screen_addr_2: ds.b 1
337+save_vbaselo: ds.b 1
338+save_linewidth: ds.b 1
339+
340+flag_vbl: ds.b 1 ; Set to true at the end of the main screen handling interupt
341+
342+ .even
343+bss_end:
344+ .end
--- public/atari/tutorials/SineWave/build.bat (nonexistent)
+++ public/atari/tutorials/SineWave/build.bat (revision 1541)
@@ -0,0 +1,40 @@
1+@ECHO OFF
2+
3+::
4+:: Convert the 408x200 picture of King Tung into an Atari format picture
5+::
6+PictConv.exe -m1 -f0 -p0 -o7 data\tutankhamun.png exported\tutankhamun.pi1
7+
8+
9+::
10+:: http://rmac.is-slick.com/manual/rmac.html#notes-for-migrating-from-other-68000-assemblers
11+::
12+:: -px -> Generate executable with extended debug symbols
13+:: -v -> Exports the list of all the sections
14+:: -s -> Warns about non optimized jumps
15+::
16+
17+
18+del SineWave.PRG 2>NUL
19+
20+SET RMAC=rmac_macro_error_test.exe
21+SET OPTIONS=-px -v -s -llisting.txt
22+
23+ECHO Assembling
24+%RMAC% %OPTIONS% SineWave.s
25+IF ERRORLEVEL 1 GOTO ErrorVasm
26+
27+::ECHO Copying into the emulator folder
28+::copy SineWave.PRG D:\_emul_\atari\_mount_\DEFENCEF.RCE\SineWave.PRG
29+
30+pause
31+goto :End
32+
33+:ErrorVasm
34+ECHO ------------------------ ERROR ------------------------
35+pause
36+goto :End
37+
38+
39+:End
40+
Show on old repository browser