mads 2.1.6 build 9 (30 Aug 22)
Source: D:\!Delphi\mads\examples\256B\LANDSCAPE\LANDSCAPE.ASM
     1 				; "Landscape", Atari XL/XE Intro 256B
     2 				; art direction by Piesiu / Agenda
     3 				; music by stRing / Agenda
     4 				; code by tr1x / Agenda
     5 				; requirements: original Atari XL/XE 64KB PAL
     6 				; version: 1.0
     7 				; release date: 2021-03-14
     8
     9 = 00C0			y	equ $00c0
    10 = 00C1			f	equ $00c1
    11 = 00C2			x	equ $00c2
    12 = 00C3			notes	equ $00c3
    13
    14 = 0012			rtclok	equ $0012
    15 = 0054			rowcrs	equ $0054
    16 = 0055			colcrs	equ $0055
    17 = 005A			oldrow	equ $005a
    18 = 005B			oldcol	equ $005b
    19 = 0224			vvblkd	equ $0224
    20 = 026F			gprior	equ $026f
    21 = 02C0			pcolr0	equ $02c0
    22 = 02C1			pcolr1	equ $02c1
    23 = 02C4			color0	equ $02c4
    24 = 02C5			color1	equ $02c5
    25 = 02C6			color2	equ $02c6
    26 = 02C8			color4	equ $02c8
    27 = 02FB			atachr	equ $02fb
    28 = D000			hposp0	equ $d000
    29 = D008			sizep0	equ $d008
    30 = D00D			grafp0	equ $d00d
    31 = D200			audf1	equ $d200
    32 = D201			audc1	equ $d201
    33 = D20A			random	equ $d20a
    34 = D40A			wsync	equ $d40a
    35 = D40B			vcount	equ $d40b
    36 = E462			xitvbv	equ $e462
    37 = EF9C			osgraph	equ $ef9c
    38 = F1A4			osprint	equ $f1a4
    39 = F1D8			ospoint	equ $f1d8
    40 = F9C2			osdraw	equ $f9c2
    41
    42
    43 					org $2000
    44
    45 				start
    46 					; enter graphics mode
    47 FFFF> 2000-20E8> A9 0F		lda #$0f
    48 2002 20 9C EF			jsr osgraph
    49
    50 					; set color palette
    51 2005 C8				iny			; Y is assumed to be 1 before "iny"
    52 2006 A9 52			lda #$52
    53 2008 99 C4 02		loopa1	sta color0,y
    54 					;clc			; not necessary
    55 200B 69 02			adc #$02
    56 200D 88				dey
    57 200E 10 F8			bpl loopa1
    58
    59 					; push PMG behind mountains
    60 2010 A0 04			ldy #$04
    61 2012 8C 6F 02			sty gprior
    62
    63 2015 88				dey
    64 2016 8C FB 02			sty atachr
    65
    66 					; the idea behind particular mountain edge can be described
    67 					; with the algorithm shown below
    68 					;
    69 					; uint8_t x = 0, y = 16, f = 0; 
    70 					; do {
    71 					;     --x;
    72 					;     f = (f - 1) * x;
    73 					;     if (f < x)
    74 					;         ++y;
    75 					;     else
    76 				        ;         --y;
    77 					;     putPixel(x >> 1, y + 32, 1);
    78 					;     if (!(x & 0xc0))
    79 					;         putPixel((x >> 1) | 0x80, y + 32 + 16, 1);
    80 					; } while (x != 0);
    81
    82 					; y = 16
    83 2019 A9 10		loopb1	lda #16
    84 201B 85 C0			sta y
    85
    86 					; x = f = 0
    87 					;lda #$00		; not necessary
    88 					;sta f
    89 					;sta x
    90
    91 201D C6 C2		loopb2	dec x			; --x
    92
    93 					; f = (f - 1) * x
    94 					; lame multiplication, but short code, and fast enough
    95 					; factor1: f
    96 					; factor2: x
    97 					; product: A and factor1 (low byte)
    98 201F A4 C1			ldy f
    99 2021 88				dey			; (f - 1)
   100 2022 A9 00			lda #$00
   101 2024 18			loopb3	clc
   102 2025 65 C2			adc x
   103 2027 88				dey
   104 2028 D0 FA			bne loopb3
   105 202A 85 C1			sta f
   106
   107 202C C5 C2			cmp x			; if (f < x)
   108 202E 90 04			bcc skipb1
   109 2030 C6 C0			dec y			; --y
   110 2032 10 02			bpl skipb2		; jmp skipa2
   111 2034 E6 C0		skipb1	inc y			; ++y
   112
   113 2036 98			skipb2	tya			; lda #$00
   114 2037 8D C8 20			sta opcodl1+1
   115 203A 8D D1 20			sta opcodl2+1
   116 203D 20 C4 20			jsr line
   117 2040 A9 80			lda #$80
   118 2042 8D C8 20			sta opcodl1+1
   119 2045 A9 10			lda #16
   120 2047 8D D1 20			sta opcodl2+1
   121 204A 20 C4 20			jsr line 
   122
   123 204D A5 C2			lda x
   124 204F D0 CC			bne loopb2
   125
   126 					; prepare data for the next hill
   127 2051 A9 60			lda #64+32
   128 2053 8D D6 20			sta opcodl5+1
   129 2056 A9 B2			lda #178
   130 2058 8D DA 20			sta opcodl6+1
   131 205B A0 4A			ldy #$4a
   132 205D 8C D2 20			sty opcodl3		; lsr
   133 2060 A2 02			ldx #$02
   134 2062 EC FB 02			cpx atachr
   135 2065 30 0D			bmi skipb3
   136 2067 8C D3 20			sty opcodl4		; lsr
   137 206A A9 A0			lda #64+64+32
   138 206C 8D D6 20			sta opcodl5+1
   139 206F A9 C0			lda #192
   140 2071 8D DA 20			sta opcodl6+1
   141
   142 2074 CE FB 02		skipb3	dec atachr
   143 2077 D0 A0			bne loopb1
   144
   145 					; initialization of positions of stars
   146 2079 A0 00			ldy #$00
   147 207B			loopc1
   148 207B A9 FE		opcodc1	lda #$fe		; PRNG seed
   149 207D 0A				asl
   150 207E 90 02			bcc skipc1
   151 2080 49 1D			eor #$1d
   152 2082 8D 7C 20		skipc1	sta opcodc1+1
   153 2085 99 E9 20			sta starpos,y
   154 2088 88				dey
   155 2089 30 F0			bmi loopc1
   156
   157 					; stars
   158 208B AD 0B D4		loopc2	lda vcount
   159 208E D0 FB			bne loopc2
   160 					;ldx #$00		; not necessary
   161 2090 BD E9 20		loopc3	lda starpos,x	
   162 2093 A0 02			ldy #$02
   163 2095 8D 0A D4			sta wsync
   164 2098 99 00 D0		loopc4	sta hposp0,y
   165 209B 0A				asl
   166 209C 88				dey
   167 209D 10 F9			bpl loopc4
   168 209F CA				dex
   169 20A0 D0 EE			bne loopc3
   170 20A2 AC 0A D2			ldy random
   171 20A5 B9 E9 20			lda starpos,y
   172 20A8 49 FF			eor #$ff
   173 20AA 99 E9 20			sta starpos,y
   174
   175 20AD A9 A3			lda #%10100011
   176 20AF 8D 01 D2			sta audc1
   177 20B2 E6 C3			inc notes
   178 20B4 A5 C3			lda notes
   179 20B6 4A				lsr
   180 20B7 4A				lsr
   181 20B8 4A				lsr
   182 20B9 4A				lsr
   183 20BA 4A				lsr
   184 20BB A8				tay
   185 20BC B9 E1 20			lda music,y
   186 20BF 8D 00 D2			sta audf1
   187
   188 20C2 50 C7			bvc loopc2		; infinite loop
   189
   190
   191 					; vertical line drawing routine
   192 20C4 A5 C2		line	lda x
   193 20C6 4A				lsr			; x >> 1
   194 20C7 09 00		opcodl1	ora #$00		; (x >> 1) | 0x80 or (x >> 1)
   195 20C9 85 5B			sta oldcol
   196 20CB 85 55			sta colcrs
   197 20CD A5 C0			lda y
   198 20CF 18				clc
   199 20D0 69 00		opcodl2	adc #$00		; y + 16 or y
   200 20D2 EA			opcodl3	nop
   201 20D3 EA			opcodl4	nop
   202 20D4 18				clc
   203 20D5 69 20		opcodl5	adc #32			; y + 32 or y + 32 + 16
   204 20D7 85 54			sta rowcrs
   205 20D9 A9 84		opcodl6	lda #132
   206 20DB 85 5A			sta oldrow
   207 20DD 20 C2 F9			jsr osdraw
   208 20E0 60				rts
   209
   210
   211 20E1 79 D9 CC D9 79 99 + music	.byte 121, 217, 204, 217, 121, 153, 162, 182
   212
   213
   214 					; positions of stars
   215 = 20E9			starpos	equ *+0
   216
   217
   218 20E9				org pcolr0
   219
   220 02C0-02C2> 2C 37 42		.byte 44, 55, 66	;$82, $84, $86 ;44, 55, 66
   221
   222
   223 02C3				org grafp0
   224
   225 D00D-D00F> 01 01 01		.byte 1, 1, 1
