mads 1.9.0 build 21 (16 Aug 09)
Source: C:\Users\Anwender\Desktop\My Dropbox\studium\nes\freezed version\beta 2\scratchalan\atalan\bin/background.asm
     1 = 000B			_arr equ 11
     2 = 000D			_TEMPB1 equ 13
     3 = 2000			PPU_REG1 equ 8192
     4 = 2001			PPU_REG2 equ 8193
     5 = 2005			PPU_SCROLL_POS equ 8197
     6 = 2002			PPU_STAT_REG equ 8194
     7 = 4014			PPU_DMA_ADR equ 16404
     8 = 000D			bgLoadPal___22 equ _TEMPB1
     9 = 000D			bgLoadNameTable___26 equ _TEMPB1
    10 = 0300			oamArray equ 768
    11 = 0000			setSprite__x equ 0
    12 = 0001			setSprite__y equ 1
    13 = 0002			setSprite__index equ 2
    14 = 0004			setSprite___32 equ 4
    15 = 0006			setSprite___33 equ 6
    16 = 0008			setSprite___34 equ 8
    17 = 000A			setSprite___37 equ 10
    18 = 000F			_s3__i equ 15
    19 				;### (0) 
    20 				    opt h-
    21  4E 45 53 1A 02 02 10 +   .byte('N', 'E', 'S', $1A, $02, $02,$10,$00,$01,$00,$00,$00,$00,$00,$00,$00)
    22 				 org $8000
    23 				RESET:
    24 8000 78			   sei
    25 8001 D8			   cld
    26 8002 A2 FF		   ldx #$FF
    27 8004 9A			   txs
    28 8005			start_example:
    29 				;### background.atl(34) waitvbl
    30 8005 20 A6 84		   jsr waitvbl
    31 				;### background.atl(35) waitvbl
    32 8008 20 A6 84		   jsr waitvbl
    33 				;### background.atl(37) setMMC1Ctrl 24
    34 800B A9 18		   lda #24
    35 800D 20 3E 85		   jsr setMMC1Ctrl
    36 				;### background.atl(38) setMMC1Prog 0
    37 8010 A9 00		   lda #0
    38 8012 20 57 85		   jsr setMMC1Prog
    39 				;### background.atl(39) setMMC1Chr0 0
    40 8015 A9 00		   lda #0
    41 8017 20 6B 85		   jsr setMMC1Chr0
    42 				;### background.atl(43) setDisplayMode %00000000 %00000000
    43 801A A9 00		   lda #0
    44 801C 8D 00 20		   sta PPU_REG1
    45 801F 8D 01 20		   sta PPU_REG2
    46 				;### background.atl(44) for i:0..255
    47 8022 85 0F		   sta _s3__i
    48 8024			_lbl11:
    49 				;### background.atl(45)       setSprite i 0 0 0 247
    50 8024 A9 00		   lda #0
    51 8026 85 00		   sta setSprite__x
    52 8028 A9 F7		   lda #247
    53 802A 85 01		   sta setSprite__y
    54 802C A5 0F		   lda _s3__i
    55 802E A2 00		   ldx #0
    56 8030 A0 00		   ldy #0
    57 8032 20 B0 84		   jsr setSprite
    58 8035 E6 0F		   inc _s3__i
    59 8037 A5 0F		   lda _s3__i
    60 8039 C9 00		   cmp #0
    61 803B D0 E7		   jne _lbl11
    62 				;### background.atl(47) bgLoadPal quizScreenPal
    63 803D A9 95		   lda #<quizScreenPal
    64 803F A2 80		   ldx #>quizScreenPal
    65 8041 20 25 85		   jsr bgLoadPal
    66 				;### background.atl(49) bgLoadNameTable quizScreenNam
    67 8044 A9 A5		   lda #<quizScreenNam
    68 8046 A2 80		   ldx #>quizScreenNam
    69 8048 20 07 85		   jsr bgLoadNameTable
    70 				;### background.atl(51) setDisplayMode %00001000 %%00111110
    71 804B A9 08		   lda #8
    72 804D 8D 00 20		   sta PPU_REG1
    73 8050 A9 3E		   lda #62
    74 8052 8D 01 20		   sta PPU_REG2
    75 				;### background.atl(53) bgSetScrolling 0 0
    76 8055 A9 00		   lda #0
    77 8057 8D 05 20		   sta PPU_SCROLL_POS
    78 805A 8D 05 20		   sta PPU_SCROLL_POS
    79 				;### background.atl(54) setSprite 0 $11 0 136 160
    80 805D A9 88		   lda #136
    81 805F 85 00		   sta setSprite__x
    82 8061 A9 A0		   lda #160
    83 8063 85 01		   sta setSprite__y
    84 8065 A9 00		   lda #0
    85 8067 A2 11		   ldx #17
    86 8069 A0 00		   ldy #0
    87 806B 20 B0 84		   jsr setSprite
    88 				;### background.atl(56) x = 0
    89 806E			main:
    90 				;### background.atl(60) waitvbl
    91 806E 20 A6 84		   jsr waitvbl
    92 				;### background.atl(62) setMMC1Chr0 0
    93 8071 A9 00		   lda #0
    94 8073 20 6B 85		   jsr setMMC1Chr0
    95 				;### background.atl(65) PPU_DMA_ADR= 3
    96 8076 A9 03		   lda #3
    97 8078 8D 14 40		   sta PPU_DMA_ADR
    98 				;### background.atl(68) spriteHit
    99 				;### nes.atl(70) 		until PPU_STAT_REG bitand 64 <> 0  
   100 807B			_lbl6:
   101 				;### nes.atl(69) 		until PPU_STAT_REG bitand 64 = 0
   102 807B AD 02 20		   lda PPU_STAT_REG
   103 807E 29 40		   and #64
   104 8080 C9 00		   cmp #0
   105 8082 D0 F7		   jne _lbl6
   106 8084			_lbl9:
   107 8084 AD 02 20		   lda PPU_STAT_REG
   108 8087 29 40		   and #64
   109 8089 C9 00		   cmp #0
   110 808B F0 F7		   jeq _lbl9
   111 808D			_lbl8:
   112 				;### background.atl(69) setMMC1Chr0 1
   113 808D A9 01		   lda #1
   114 808F 20 6B 85		   jsr setMMC1Chr0
   115 				;### background.atl(73) goto main
   116 8092 4C 6E 80		   jmp main
   117 8095			quizScreenPal:
   118 				;### background.atl(27) const quizScreenPal:bgPal       = file "test.pal"
   119 8095 0F 30 0C 10 00 01 +    ins 'test.pal'
   120 80A5			quizScreenNam:
   121 				;### background.atl(28) const quizScreenNam:bgNameTable = file "face.nam"
   122 80A5 00 00 00 00 00 00 +    ins 'face.nam'
   123 84A5 60			   rts
   124 84A6			waitvbl .proc
   125 84A6			_lbl3:
   126 				;### nes.atl(65) 		until PPU_STAT_REG bitand 128 <> 0 
   127 84A6 AD 02 20		   lda PPU_STAT_REG
   128 84A9 29 80		   and #128
   129 84AB C9 00		   cmp #0
   130 84AD F0 F7		   jeq _lbl3
   131 84AF			_lbl2:
   132 84AF 60			   rts
   133 				.endp
   134 84B0			setSprite .proc
   135 84B0 84 0A		   sty setSprite___37
   136 				;### nes_sprite.atl(27) 		  index = oamnr * 4
   137 84B2 0A			   asl
   138 84B3 85 02		   sta setSprite__index-0
   139 84B5 A9 00		   lda #0
   140 84B7 2A			   rol
   141 84B8 06 02		   asl setSprite__index-0
   142 84BA 2A			   rol
   143 84BB 85 03		   sta setSprite__index-0+1
   144 				;### nes_sprite.atl(28) 		  oamArray(index) = y
   145 84BD A9 00		   lda #<oamArray
   146 84BF 85 0B		   sta _arr-0
   147 84C1 A9 03		   lda #>oamArray
   148 84C3 18			   clc
   149 84C4 65 03		   adc setSprite__index+1
   150 84C6 85 0C		   sta _arr-0+1
   151 84C8 A4 02		   ldy setSprite__index-0+0
   152 84CA A5 01		   lda setSprite__y
   153 84CC 91 0B		   sta (_arr),y
   154 				;### nes_sprite.atl(29) 		  oamArray(index + 1) = nr
   155 84CE A5 02		   lda setSprite__index-0
   156 84D0 18			   clc
   157 84D1 69 01		   adc #1
   158 84D3 A8			   tay
   159 84D4 A5 03		   lda setSprite__index-0+1
   160 84D6 69 00		   adc #0
   161 84D8 85 05		   sta setSprite___32-0+1
   162 84DA A9 03		   lda #>oamArray
   163 84DC 18			   clc
   164 84DD 65 05		   adc setSprite___32+1
   165 84DF 85 0C		   sta _arr-0+1
   166 84E1 8A			   txa
   167 84E2 91 0B		   sta (_arr),y
   168 				;### nes_sprite.atl(30) 		  oamArray(index + 2) = palNr
   169 84E4 A5 02		   lda setSprite__index-0
   170 84E6 18			   clc
   171 84E7 69 02		   adc #2
   172 84E9 A8			   tay
   173 84EA A5 03		   lda setSprite__index-0+1
   174 84EC 69 00		   adc #0
   175 84EE 85 07		   sta setSprite___33-0+1
   176 84F0 18			   clc
   177 84F1 A5 0A		   lda setSprite___37
   178 84F3 91 0B		   sta (_arr),y
   179 				;### nes_sprite.atl(31) 		  oamArray(index + 3) = x
   180 84F5 A5 02		   lda setSprite__index-0
   181 84F7 18			   clc
   182 84F8 69 03		   adc #3
   183 84FA A8			   tay
   184 84FB A5 03		   lda setSprite__index-0+1
   185 84FD 69 00		   adc #0
   186 84FF 85 09		   sta setSprite___34-0+1
   187 8501 18			   clc
   188 8502 A5 00		   lda setSprite__x
   189 8504 91 0B		   sta (_arr),y
   190 8506 60			   rts
   191 				.endp
   192 8507			   icl 'C:\Users\Anwender\Desktop\My Dropbox\studium\nes\freezed version\beta 2\scratchalan\atalan\platform\nes\nes.asm'
Source: C:\Users\Anwender\Desktop\My Dropbox\studium\nes\freezed version\beta 2\scratchalan\atalan\platform\nes\nes.asm
     1 8507			_adr_putchr .proc
     2 				;Write byte to address specified by _arr and increment the address by 1.
     3 						 	
     4 				;	write the char to specified address	
     5 				;	ldy #0
     6 				;	sta (_arr),y
     7
     8 				;	inc _arr
     9 				;	bne skip1
    10 				;	inc _arr+1
    11 				;skip1
    12 				;	rts
    13 				.endp
    14
    15 8507			_out_putchr .proc
    16 				;Write character from A to output.
    17 				;	
    18 				;		tax
    19 				;		lda $347	;ICPUTB+1
    20 				;		pha
    21 				;		lda $346	;ICPUTB
    22 				;		pha
    23 				;		txa
    24 						rts
    25
    26 				.endp
   193 8507			   icl 'C:\Users\Anwender\Desktop\My Dropbox\studium\nes\freezed version\beta 2\scratchalan\atalan\processor\m6502\m6502.asm'
Source: C:\Users\Anwender\Desktop\My Dropbox\studium\nes\freezed version\beta 2\scratchalan\atalan\processor\m6502\m6502.asm
     1 				;********************************************************
     2 				;
     3 				;  ATALAN 6502 processor definition support routines
     4 				;
     5 				;  Parts of code have been taken from Effectus library.
     6 				;
     7 				;********************************************************
     8
     9
    10 				;Noname
    11 				;651-655         028B-028F
    12 				;
    13 				;More spare bytes that you shouldn't use because future versions of the OS might use them. 
    14 				;Locations 651 and 652 are already used by version "B" as part of the interrupt handler routines.
    15
    16 				;OS registers we use as temporary:
    17 				;
    18 				;BUFRLO,BUFRHI   50,51 $32,$33
    19 				;BFENLO,BFENHI   52,53 $34,$35
    20
    21 				;ADRESS  100,101   $64,$65  A temporary storage location used by the display handler for so many things that it made my mind spin and I forgot what they were.
    22 				;MLTTMP  102,103   $66,$67  More temporary storage, with aliases OPNTMP and TOADR.
    23 				;SAVADR  104,105   $68,$69  Also know as FRMADR. Also used for temporary storage. 
    24 				;                           Also not significant enough to explain (look at the OS listing if, for some reason, you really care).
    25
    26 				;Registers used when drawing line
    27 				;ROWAC   112,113   $70,$71
    28 				;COLAC   114,115   $72,$73
    29 				;ENDPT   116,117   $74,$75
    30 				;COUNTR  126,127   $7E,$7F  COUNTR tells how many points have to be plotted before the line is finished.
    31
    32 				;
    33 = 0001			_SYS_PRINT_SIGNED = 1
    34
    35 				;_putchr_proc_adr = $653  ;+$654 
    36 = 0032			?argptr =   $32		;$33
    37 = 0034			?varptr	=	$34
    38 = 0015			?size	=	$15		;15		//$16 BUFADR
    39 						.IF _SYS_PRINT_SIGNED = 1 
    40 = 0016			?sign = $16
    41 						.ENDIF
    42 = 0038			?aux2	=	$38
    43 = 0039			?aux	=	$39
    44
    45 				;Following assigns are defined by mc6502.atl
    46
    47 = 0032			_TW1 = $32	;$33  mc6502.atl defines these labels as _TEMPW1, _TEMPW2.
    48 = 0034			_TW2 = $34  ;$35
    49 = 0015			_TW3 = $15	;$16
    50 = 0070			_TL1 = $70	;four byte register ($70-$73) defined under name _TEMPL1 in mc6502.atl		
    51
    52 				;_stdbuf    = $600		;TODO: use LINBUF ($247-$26E)  (100,101 can point to it)
    53
    54 				;Argument list:
    55 				;	0	end of list
    56 				;	1..127  Constant string of specified lenght
    57 				; 128     EOL
    58
    59 				;   7 6 5 4 3 2 1 0 
    60 				;  |0| | | | | | | |		String of length 0..127
    61 				;  |1|0|0| | | | | |    Pointer to unsigned integer of length 1..31 bytes
    62 				;  |1|0|1| | | | | |    Pointer to signed integer of length 1..31 bytes
    63
    64 				;         ---- ptr to unsigned integer ---- (7-bit set)
    65 				; 129     one byte integer reference
    66 				;	130     two byte integer reference
    67 				;	131     three byte integer eference
    68 				;	132     four byte integer reference
    69 				;         ---- ptr to signed -----  (5-bit set)
    70 				; 161     one byte
    71 				; 162     two byte
    72 				; 163     three byte
    73 				; 164     four byte
    74
    75 8507			_std_print_adr .proc
    76
    77 						lda #<_adr_putchr
    78 						ldx #>_adr_putchr
    79 						clc
    80 						bcc system__print
    81 						.endp
    82 						
    83 8507			_std_print_out .proc
    84 						lda #<_out_putchr
    85 						ldx #>_out_putchr
    86 						clc											;TODO: No Jump, if we are directly before the _std_print
    87 						bcc system__print
    88 						.endp
    89
    90 				 .IF .NOT .DEF _EOL_CHAR
    91 						_EOL_CHAR equ 0
    92 				 .ENDIF
    93
    94 8507			system__print .proc
    95 						sta _putchr_proc_adr 
    96 						stx _putchr_proc_adr+1
    97 						
    98 						;... continue to _std_print
    99 				;.endp
   100 						
   101 				;_std_print	.proc
   102
   103 						;Get address of argument from stack
   104 						pla
   105 						sta ?argptr
   106 						pla
   107 						sta ?argptr+1
   108 						jsr _read_byte	;just skip next byte (that is part of return address)
   109
   110 						;Read command from input				
   111 8507			command
   112 						jsr _read_byte
   113 						sta ?size
   114 						tay				; to set the flags
   115 						beq done		;command 0 means end of sequence
   116 						bpl str			;1..127 constant string
   117
   118 						;Write n-byte integer variable
   119
   120 						and #$7f		; zero top bit (it's always 1)
   121 						sta ?size
   122 						beq eol			;size 0 means end of line (0 byte integer would be nonsense)
   123
   124 				    ;Read address of the variable
   125
   126 						jsr _read_byte
   127 						sta ?varptr		
   128 						jsr _read_byte
   129 						sta ?varptr+1
   130
   131 						.IF _SYS_PRINT_SIGNED = 1 
   132 						;signed number has bit 5 set
   133 						lda #0
   134 						sta ?sign
   135 						
   136 						lda ?size
   137 				    and #32		;%00100000
   138 				    beq unsigned
   139
   140 						lda ?size	;size uses only 4 bits
   141 						and #31		;%00011111
   142 						sta ?size
   143 				    
   144 				    tay				;test, whether the integer is negative (i.e. top byte is negative)
   145 				    dey
   146 				    lda (?varptr),y
   147 				    bpl unsigned
   148 						 
   149 				    dec ?sign				;sign = $ff  (-1)
   150 						
   151 						lda #'-'
   152 						jsr _std_putchr
   153 						
   154 8507			unsigned
   155 						.ENDIF
   156 						    
   157 						jsr _std_bin_to_bcd
   158 						jsr _std_print_hex
   159 						clc
   160 						bcc command		;jmp command
   161 8507			eol
   162 						lda #_EOL_CHAR	
   163 						jsr _std_putchr
   164 						clc
   165 						bcc command		;jmp command
   166 						;Write constant string (size is 1..127, already stored)
   167 									
   168 8507			str
   169 						jsr _read_byte
   170 						jsr _std_putchr
   171 						dec ?size
   172 						bne str
   173 						beq	command
   174 										
   175 8507			done		
   176 						jmp (?argptr)	
   177 						rts
   178 						
   179 8507			_read_byte
   180 						ldy #0
   181 						lda (?argptr),y
   182 						inc ?argptr
   183 						bne skip
   184 						inc ?argptr+1
   185 8507			skip
   186 						rts
   187 				.endp
   188
   189 8507			_std_putchr .proc
   190 						jmp (_putchr_proc_adr)
   191 						rts
   192 				.endp
   193
   194
   195 8507			.proc _std_print_hex
   196 				;Print hexadecimal number of arbitrary length (?size). 
   197 				;Leading zeroes are not printed.
   198 				;In:
   199 				;	?varptr		Pointer to memory containing the number
   200 				;	?size		  Number of bytes to print
   201 				;Uses:
   202 				;	?aux
   203 				;	?aux2
   204 					
   205 						lda ?size
   206 						sta ?aux
   207 						lda #0
   208 						sta ?aux2		; number of non-zero digits on output
   209 						beq _loop
   210 8507			_outbyte
   211 						ldy ?aux		
   212 						lda (?varptr),y
   213 						pha
   214 						lsr
   215 						lsr
   216 						lsr
   217 						lsr
   218 						jsr _write_digit
   219 					
   220 						pla
   221 						and #$0f
   222 						jsr _write_digit
   223 8507			_loop	
   224 						dec ?aux
   225 						bpl _outbyte
   226 						
   227 						;If no character has been written, write at least one 0		
   228 						lda ?aux2
   229 						bne _no_empty
   230 						lda #48
   231 						jsr _std_putchr
   232 8507			_no_empty
   233 				 
   234 						rts
   235 					
   236 8507			_write_digit
   237 				;In: a 4 bit digit
   238
   239 						tax
   240 						bne _non_zero
   241 						lda ?aux2
   242 						beq _done		;this is zero and there has been no char before - no output
   243 8507			_non_zero
   244 						lda hex,x
   245 						jsr _std_putchr
   246 						inc ?aux2
   247 8507			_done
   248 						rts
   249
   250 8507			hex     dta c"0123456789ABCDEF"
   251
   252 				.endp
   253
   254 8507			.proc _std_bin_to_bcd
   255 				;Convert binary number to BCD. 
   256 				;Arbitrary size (up to 127 bytes) are supported.
   257 				;In:
   258 				;	?varptr	pointer to binary number
   259 				; a   0 means unsigned number
   260 				;     $ff means signed number
   261 				;	?size	number of bytes
   262 				;Out:
   263 				;	?size	on output, returns size of resulting bcd number
   264 				;   ?varptr	on output, containg pointer to converted BCD
   265 				;Uses:
   266 				;	_stdbuf
   267 				;	?aux
   268 				;	?aux2
   269
   270 						;Compute size of resulting number 
   271 						ldy ?size
   272 						sty ?aux		; used to count later
   273 						iny				;add space to result
   274 						sty ?size
   275 						
   276 						;Zero the destination buffer
   277 						lda #0
   278 8507			zero	sta _stdbuf-1,y
   279 						dey
   280 						bne zero
   281 						
   282 						;**** We convert the number byte a time
   283 						sed
   284 						
   285 						;?aux = varptr(?aux)
   286 8507			bytes
   287 						dec ?aux
   288 						ldy ?aux
   289 						lda (?varptr),y	
   290 						.IF _SYS_PRINT_SIGNED = 1 
   291 						eor ?sign
   292 						.ENDIF	
   293 						sta ?aux2
   294 						sec				;set top bit to 1
   295 						bcs loop		
   296
   297 8507			shift_byte			
   298 						ldx #0
   299 						ldy ?size
   300 8507			bcd_mul2
   301 						lda _stdbuf,x
   302 						adc	_stdbuf,x			;buf2(x) = buf2(x) * 2 + carry
   303 						sta _stdbuf,x
   304 						inx
   305 						dey								;TODO: cpx ?size
   306 						bne bcd_mul2
   307 							
   308 						clc
   309 8507			loop	rol ?aux2		;divide by two, if result is 0, end
   310 						bne shift_byte		
   311 						
   312 						lda ?aux
   313 						bne bytes
   314 					
   315 						.IF _SYS_PRINT_SIGNED = 1 
   316 						;If this is negative number, add 1
   317 						;In case sign is $ff, asl will set the C to 1, otherwise to 0	
   318 						lda ?sign
   319 						asl
   320 						ldx #0
   321 8507			carry1
   322 						lda _stdbuf,x
   323 						adc #0
   324 						sta _stdbuf,x
   325 						inx
   326 						bcs carry1
   327 						.ENDIF
   328 									
   329 						cld		
   330 						
   331 						lda #<_stdbuf
   332 						sta ?varptr	
   333 						lda #>_stdbuf
   334 						sta ?varptr+1	
   335 						rts
   336
   337 				.endp
   338 				 
   339 				/*
   340 				  Mul8 - 8-bit multiplication routine
   341 				  
   342 				  Original source:
   343 				  Book Atari Roots (Chapter Ten - Assembly Language Math)
   344 				  Hyperlink: http://www.atariarchives.org/roots/chapter_10.php
   345 				  
   346 				  Parameters:
   347 					  a First multiplicant
   348 					  x Second multiplicant
   349 				  Result: 
   350 						TEMPW2,TEMPW2+1	high byte of the result
   351 				*/
   351
   352
   353 8507			_sys_mul8  .proc
   354
   355 = 0032			MUL1 = _TW1
   356 = 0033			MUL2 = _TW1+1
   357 = 0034			RES  = _TW2		;_TW2+1
   358
   359 						sta MUL1			;input comes in A and X
   360 						stx MUL2
   361 						
   362 						lda #0			;RES = 0
   363 						sta RES
   364 						
   365 						ldx #8  
   366 8507			loop
   367 						lsr MUL1		;MUL1 = MUL1 / 2
   368 						bcc noadd
   369 						
   370 						clc					;RES = RES + (MUL2 * $ff)
   371 						adc MUL2	  
   372 8507			noadd 
   373 						ror @				;RES = RES / 2		(Carry is 0, when there was no add)
   374 						ror RES
   375
   376 						dex
   377 						bne loop
   378 						
   379 						sta RES+1
   380 						rts
   381
   382 						.endp
   383
   384 				/*
   385 				  Mul16 - 16-bit multiplication routine
   386 				    
   387 				  Parameters:
   388 					  _TW1 First multiplicant (we use only two bytes now)
   389 					  _TW2 Second multiplicant
   390 				  Result: 
   391 						_TL1 Result
   392 				*/
   392
   393
   394 8507			_sys_mul16  .proc
   395
   396 = 0032			MUL1 = _TW1
   397 = 0034			MUL2 = _TW2
   398 = 0070			RES  = _TL1
   399 						
   400 						lda #0      ;RES = 0;
   401 						sta RES
   402 						sta RES+1
   403 						sta RES+2
   404 						sta RES+3
   405 						
   406 						ldx #16  
   407 8507			loop
   408 						lsr MUL1+1		;MUL1 = MUL1 / 2
   409 						ror MUL1
   410 						bcc noadd
   411 						
   412 						lda RES+2			;RES = RES + (MUL2 * $ffff)  (only upper half) 
   413 						clc		
   414 						adc MUL2
   415 						sta RES+2
   416 						lda RES+3
   417 						adc MUL2+1
   418 						sta RES+3
   419 8507			noadd
   420 						ror RES+3				;RES = RES / 2		(Carry is 0, when there was no add)
   421 						ror RES+2
   422 						ror RES+1
   423 						ror RES+0
   424 						 
   425 						dex
   426 						bne loop
   427 						
   428 						rts
   429
   430 						.endp
   431 				 
   432 				/*
   433 				  Div8 - 8-bit division routine
   434 				 
   435 				  Original source:
   436 				  Book Atari Roots (Chapter Ten - Assembly Language Math)
   437 				  Hyperlink: http://www.atariarchives.org/roots/chapter_10.php
   438 				 
   439 				  Parameters:
   440 				  _TEMPW1		16-bit dividend
   441 				  a					 p1_math:  8-bit divisor
   442 				  x          number of bits of an divisir (8 max)
   443 				 
   444 				  Result:
   445 				  x STORE1: 8-bit quotient
   446 				  a STORE2: 8-bit remainder
   447 				*/
   447
   448
   449 8507			_sys_div8  .proc
   450 				  ldx #08  ; For an 8-bit divisor
   451 					
   452 8507			_sys_div
   453
   454 = 0034			divisor  = _TW2
   455 = 0035			quotient = _TW2+1
   456
   457 				  sta divisor
   458 					lda #0     				; for non-8 divis
   459 					sta quotient
   460 				  lda _TW1+1
   461 				  sec 
   462 				  sbc divisor
   463 8507			dloop 
   464 				  php  					; The loop that divides 
   465 				  rol quotient
   466 				  asl _TW1
   467 				  rol @
   468 				  plp
   469 				  bcc addit
   470 				  sbc divisor
   471 				  jmp next
   472 8507			addit 
   473 				  adc divisor
   474 8507			next  
   475 				  dex
   476 				  bne dloop
   477 				  bcs fini
   478 				  adc divisor
   479 				  clc
   480 8507			fini
   481 					tax            ; x = remainder
   482 				  lda quotient   ; a = quotient
   483 				  rol
   484 				  rts
   485 				 
   486 				  .endp
   487
   488 				/*
   489
   490 				  Square Root
   491
   492 				  Calculates the 8 bit root and 9 bit remainder of a 16 bit unsigned integer in
   493 				  Numberl/Numberh. The result is always in the range 0 to 255 and is held in
   494 				  Root, the remainder is in the range 0 to 511 and is held in Reml/Remh
   495
   496 				  partial results are held in templ/temph
   497
   498 				  Destroys A, X registers.
   499
   500 					Arguments:
   501 					
   502 					_TEMPW1  16-bit number to compute root of
   503 					
   504 					<a        Square root
   505 					<_TEMPW2  Remainder of square
   506 					
   507 				*/
   507
   508
   509 8507			_sys_sqrt16 .proc
   510
   511 = 0032			Numberl		= _TW1		; number to find square root of low byte
   512 = 0033			Numberh		= _TW1+1	; number to find square root of high byte
   513 = 0034			Reml		  = _TW2		; remainder low byte
   514 = 0035			Remh		  = _TW2+1	; remainder high byte
   515 = 0070			templ		  = _TL1		; temp partial low byte
   516 = 0071			temph		  = _TL1+1	; temp partial high byte
   517 = 0072			Root		  = _TL1+2	; square root
   518
   519 					LDA	#$00		; clear A
   520 					STA	Reml		; clear remainder low byte
   521 					STA	Remh		; clear remainder high byte
   522 					STA	Root		; clear Root
   523 					LDX	#$08		; 8 pairs of bits to do
   524 8507			Loop
   525 					ASL	Root		; Root = Root * 2
   526
   527 					ASL	Numberl		; shift highest bit of number ..
   528 					ROL	Numberh		;
   529 					ROL	Reml		; .. into remainder
   530 					ROL	Remh		;
   531
   532 					ASL	Numberl		; shift highest bit of number ..
   533 					ROL	Numberh		;
   534 					ROL	Reml		; .. into remainder
   535 					ROL	Remh		;
   536
   537 					LDA	Root		; copy Root ..
   538 					STA	templ		; .. to templ
   539 					LDA	#$00		; clear byte
   540 					STA	temph		; clear temp high byte
   541
   542 					SEC			; +1
   543 					ROL	templ		; temp = temp * 2 + 1
   544 					ROL	temph		;
   545
   546 					LDA	Remh		; get remainder high byte
   547 					CMP	temph		; comapre with partial high byte
   548 					BCC	Next		; skip sub if remainder high byte smaller
   549
   550 					BNE	Subtr		; do sub if <> (must be remainder>partial !)
   551
   552 					LDA	Reml		; get remainder low byte
   553 					CMP	templ		; comapre with partial low byte
   554 					BCC	Next		; skip sub if remainder low byte smaller
   555
   556 								; else remainder>=partial so subtract then
   557 								; and add 1 to root. carry is always set here
   558 8507			Subtr
   559 					LDA	Reml		; get remainder low byte
   560 					SBC	templ		; subtract partial low byte
   561 					STA	Reml		; save remainder low byte
   562 					LDA	Remh		; get remainder high byte
   563 					SBC	temph		; subtract partial high byte
   564 					STA	Remh		; save remainder high byte
   565
   566 					INC	Root		; increment Root
   567 8507			Next
   568 					DEX			; decrement bit pair count
   569 					BNE	Loop		; loop if not all done
   570
   571 					lda Root
   572 					
   573 					RTS
   574 				.endp
   194 8507			   icl 'C:\Users\Anwender\Desktop\My Dropbox\studium\nes\freezed version\beta 2\scratchalan\atalan\platform\nes\nes_bg.asm'
Source: C:\Users\Anwender\Desktop\My Dropbox\studium\nes\freezed version\beta 2\scratchalan\atalan\platform\nes\nes_bg.asm
     1 				;********************************
     2 				;ATALAN nes background asm functions
     3 				;********************************
     4 				; created by Marcel Cevani 31.01.2011
     5 				; tnx to Atalan the snake & rudla :)
     6
     7 				;_TEMPB1 equ 54  array offset
     8 				;_TEMPB2 equ 55  array offset
     9
    10 				; ATALAN code
    11 				; PPU_DATA_ADR = $20
    12 				; PPU_DATA_ADR = $00
    13 				; for x:0..1023
    14 				;       PPU_DATA = titleNametable(x)
    15
    16 8507			bgLoadNameTable .proc
    17 8507 85 0D					sta _TEMPB1
    18 8509 86 0E					stx _TEMPB1+1
    19 							;tsc 
    20 850B A0 00					ldy #$00
    21 							;ldy #$20
    22 850D A2 04					ldx #04
    23 850F A9 20					lda #$20 
    24 8511			copyArray: 
    25 8511 8D 06 20					sta $2006
    26 8514 8C 06 20					sty $2006
    27 8517			cpyloop_n: 
    28 8517 B1 0D					lda (_TEMPB1),y
    29 8519 8D 07 20					sta $2007
    30 851C C8						iny
    31 851D D0 F8					bne cpyloop_n
    32 851F E6 0E					inc _TEMPB1+1
    33 8521 CA						dex
    34 8522 D0 F3					bne cpyloop_n 
    35 8524 60						rts
    36 							.endp
    37
    38 				;  ATALAN code	 
    39 				;  PPU_DATA_ADR = $3F
    40 				;  PPU_DATA_ADR = $00
    41 				;  for i:0..15
    42 				;        PPU_DATA  = bgPal(i)
    43 							    
    44 8525			bgLoadPal .proc
    45 8525 85 0D					sta _TEMPB1
    46 8527 86 0E					stx _TEMPB1+1
    47 8529 A0 00					ldy #$00
    48 852B A9 3F					lda #$3F
    49 852D			copyArray: 
    50 852D 8D 06 20					sta $2006
    51 8530 8C 06 20					sty $2006
    52 8533			cpyloop_p: 
    53 8533 B1 0D					lda (_TEMPB1),y
    54 8535 8D 07 20					sta $2007
    55 8538 C8						iny
    56 8539 C0 10					cpy #$10
    57 853B D0 F6					bne cpyloop_p 
    58 853D 60						rts
    59 							.endp
   195 853E			   icl 'C:\Users\Anwender\Desktop\My Dropbox\studium\nes\freezed version\beta 2\scratchalan\atalan\platform\nes\nes_sprite.asm'
Source: C:\Users\Anwender\Desktop\My Dropbox\studium\nes\freezed version\beta 2\scratchalan\atalan\platform\nes\nes_sprite.asm
     1 				;********************************
     2 				;ATALAN nes sprite asm functions
     3 				;********************************
     4 				; created by Marcel Cevani 31.01.2011
     5 				; tnx to Atalan the snake & rudla :)
     6
     7 				;_TEMPB1 equ 54  array offset
     8 				;_TEMPB2 equ 55  array offset
     9
    10 				;  ATALAN code	 
    11 				;  PPU_DATA_ADR = $3F
    12 				;  PPU_DATA_ADR = $10
    13 				;  for i:0..15
    14 				;        PPU_DATA  = spritePal(i)
    15 							    
    16 853E			sprLoadPal .proc
    17 							sta _TEMPB1
    18 							stx _TEMPB1+1
    19 							ldx #$10
    20 							ldy #$00
    21 							lda #$3F
    22 853E			copyArray:  sta $2006
    23 							stx $2006
    24 853E			cpyloop_sr: lda (_TEMPB1),y
    25 							sta $2007
    26 							iny
    27 							cpy #$10
    28 							bne cpyloop_sr 
    29 							rts
    30 							.endp
    31
   196 853E			   icl 'C:\Users\Anwender\Desktop\My Dropbox\studium\nes\freezed version\beta 2\scratchalan\atalan\platform\nes\nes_mmc1.asm'
Source: C:\Users\Anwender\Desktop\My Dropbox\studium\nes\freezed version\beta 2\scratchalan\atalan\platform\nes\nes_mmc1.asm
     1 				;  code addapted from http://wiki.nesdev.com/w/index.php/Programming_MMC1
     2
     3 853E			setMMC1Ctrl .proc
     4 							; reset shift reg
     5 853E A2 80					LDX #$80
     6 8540 8E 00 80					STX $8000
     7 							; now write 
     8 8543 8D 00 80					STA $8000
     9 8546 4A						LSR
    10 8547 8D 00 80					STA $8000
    11 854A 4A						LSR
    12 854B 8D 00 80					STA $8000
    13 854E 4A						LSR
    14 854F 8D 00 80					STA $8000
    15 8552 4A						LSR
    16 8553 8D 00 80					STA $8000
    17 8556 60						rts
    18 							.endp
    19
    20
    21 8557			setMMC1Prog .proc
    22 8557 8D 00 E0					STA $E000
    23 855A 4A						LSR
    24 855B 8D 00 E0					STA $E000
    25 855E 4A						LSR
    26 855F 8D 00 E0					STA $E000
    27 8562 4A						LSR
    28 8563 8D 00 E0					STA $E000
    29 8566 4A						LSR
    30 8567 8D 00 E0					STA $E000
    31 856A 60						rts
    32 							.endp
    33
    34
    35 856B			setMMC1Chr0 .proc 
    36 856B 8D 00 A0					STA $A000
    37 856E 4A						LSR
    38 856F 8D 00 A0					STA $A000
    39 8572 4A						LSR
    40 8573 8D 00 A0					STA $A000
    41 8576 4A						LSR
    42 8577 8D 00 A0					STA $A000
    43 857A 4A						LSR
    44 857B 8D 00 A0					STA $A000
    45 857E 60						rts
    46 							.endp
    47
    48 857F			setMMC1Chr1 .proc 
    49 							STA $C000
    50 							LSR
    51 							STA $C000
    52 							LSR
    53 							STA $C000
    54 							LSR
    55 							STA $C000
    56 							LSR
    57 							STA $C000
    58 							rts
    59 							.endp
   197 857F 00 00 00 00 00 00 +     .align $FFF9,$00
   198 FFF9			NMI:
   199 FFF9 40			    rti
   200 FFFA			   org $FFFA
   201 FFFA 00 80		   .dw RESET
   202 FFFC 00 80		  .dw RESET
   203 FFFE 00 00		   .dw 0
