Debian Codegraph @

machines/atari2600/macro.h

raw symbols SCIP
1 ; MACRO.H
2 ; Version 1.09, 05/SEP/2020
3
4 VERSION_MACRO = 109
5
6 ;
7 ; THIS FILE IS EXPLICITLY SUPPORTED AS A DASM-PREFERRED COMPANION FILE
8 ; The latest version can be found at https://dasm-assembler.github.io/
9 ;
10 ; This file defines DASM macros useful for development for the Atari 2600.
11 ; It is distributed as a companion machine-specific support package
12 ; for the DASM compiler.
13 ;
14 ; Many thanks to the people who have contributed. If you find an issue with the
15 ; contents, or would like ot add something, please report as an issue at...
16 ; https://github.com/dasm-assembler/dasm/issues
17
18
19 ; Latest Revisions...
20 ; 1.09 05/SEP/2020 - updated license/links
21
22 ; 1.08 13/JUL/2020 - added use of LXA to CLEAN_START
23 ; 1.07 19/JAN/2020 - correction to comment VERTICAL_SYNC
24 ; 1.06 03/SEP/2004 - nice revision of VERTICAL_SYNC (Edwin Blink)
25 ; 1.05 14/NOV/2003 - Added VERSION_MACRO equate (which will reflect 100x version #)
26 ; This will allow conditional code to verify MACRO.H being
27 ; used for code assembly.
28 ; 1.04 13/NOV/2003 - SET_POINTER macro added (16-bit address load)
29 ;
30 ; 1.03 23/JUN/2003 - CLEAN_START macro added - clears TIA, RAM, registers
31 ;
32 ; 1.02 14/JUN/2003 - VERTICAL_SYNC macro added
33 ; (standardised macro for vertical synch code)
34 ; 1.01 22/MAR/2003 - SLEEP macro added.
35 ; - NO_ILLEGAL_OPCODES switch implemented
36 ; 1.0 22/MAR/2003 Initial release
37
38 ; Note: These macros use illegal opcodes. To disable illegal opcode usage,
39 ; define the symbol NO_ILLEGAL_OPCODES (-DNO_ILLEGAL_OPCODES=1 on command-line).
40 ; If you do not allow illegal opcode usage, you must include this file
41 ; *after* including VCS.H (as the non-illegal opcodes access hardware
42 ; registers and require them to be defined first).
43
44 ; Available macros...
45 ; SLEEP n - sleep for n cycles
46 ; VERTICAL_SYNC - correct 3 scanline vertical synch code
47 ; CLEAN_START - set machine to known state on startup
48 ; SET_POINTER - load a 16-bit absolute to a 16-bit variable
49
50 ;-------------------------------------------------------------------------------
51 ; SLEEP duration
52 ; Original author: Thomas Jentzsch
53 ; Inserts code which takes the specified number of cycles to execute. This is
54 ; useful for code where precise timing is required.
55 ; ILLEGAL-OPCODE VERSION DOES NOT AFFECT FLAGS OR REGISTERS.
56 ; LEGAL OPCODE VERSION MAY AFFECT FLAGS
57 ; Uses illegal opcode (DASM 2.20.01 onwards).
58
59 MAC SLEEP ;usage: SLEEP n (n>1)
60 .CYCLES SET {1}
61
62 IF .CYCLES < 2
63 ECHO "MACRO ERROR: 'SLEEP': Duration must be > 1"
64 ERR
65 ENDIF
66
67 IF .CYCLES & 1
68 IFNCONST NO_ILLEGAL_OPCODES
69 nop 0
70 ELSE
71 bit VSYNC
72 ENDIF
73 .CYCLES SET .CYCLES - 3
74 ENDIF
75
76 REPEAT .CYCLES / 2
77 nop
78 REPEND
79 ENDM
80
81 ;-------------------------------------------------------------------------------
82 ; VERTICAL_SYNC
83 ; revised version by Edwin Blink -- saves bytes!
84 ; Inserts the code required for a proper 3 scanline vertical sync sequence
85 ; Note: Alters the accumulator
86
87 ; OUT: A = 0
88
89 MAC VERTICAL_SYNC
90 lda #%1110 ; each '1' bits generate a VSYNC ON line (bits 1..3)
91 .VSLP1 sta WSYNC ; 1st '0' bit resets Vsync, 2nd '0' bit exit loop
92 sta VSYNC
93 lsr
94 bne .VSLP1 ; branch until VYSNC has been reset
95 ENDM
96
97 ;-------------------------------------------------------------------------------
98 ; CLEAN_START
99 ; Original author: Andrew Davie
100 ; Standardised start-up code, clears stack, all TIA registers and RAM to 0
101 ; Sets stack pointer to $FF, and all registers to 0
102 ; Sets decimal mode off, sets interrupt flag (kind of un-necessary)
103 ; Use as very first section of code on boot (ie: at reset)
104 ; Code written to minimise total ROM usage - uses weird 6502 knowledge :)
105
106 MAC CLEAN_START
107 sei
108 cld
109
110 IFNCONST NO_ILLEGAL_OPCODES
111 lxa #0
112 ELSE
113 ldx #0
114 txa
115 ENDIF
116 tay
117 .CLEAR_STACK dex
118 txs
119 pha
120 bne .CLEAR_STACK ; SP=$FF, X = A = Y = 0
121
122 ENDM
123
124 ;-------------------------------------------------------
125 ; SET_POINTER
126 ; Original author: Manuel Rotschkar
127 ;
128 ; Sets a 2 byte RAM pointer to an absolute address.
129 ;
130 ; Usage: SET_POINTER pointer, address
131 ; Example: SET_POINTER SpritePTR, SpriteData
132 ;
133 ; Note: Alters the accumulator, NZ flags
134 ; IN 1: 2 byte RAM location reserved for pointer
135 ; IN 2: absolute address
136
137 MAC SET_POINTER
138 .POINTER SET {1}
139 .ADDRESS SET {2}
140
141 LDA #<.ADDRESS ; Get Lowbyte of Address
142 STA .POINTER ; Store in pointer
143 LDA #>.ADDRESS ; Get Hibyte of Address
144 STA .POINTER+1 ; Store in pointer+1
145
146 ENDM
147
148 ;-------------------------------------------------------
149 ; BOUNDARY byte#
150 ; Original author: Denis Debro (borrowed from Bob Smith / Thomas)
151 ;
152 ; Push data to a certain position inside a page and keep count of how
153 ; many free bytes the programmer will have.
154 ;
155 ; eg: BOUNDARY 5 ; position at byte #5 in page
156
157 .FREE_BYTES SET 0
158 MAC BOUNDARY
159 REPEAT 256
160 IF <. % {1} = 0
161 MEXIT
162 ELSE
163 .FREE_BYTES SET .FREE_BYTES + 1
164 .byte $00
165 ENDIF
166 REPEND
167 ENDM
168
169
170 ; EOF