Jump to content
IGNORED

How do I do a loop in assembler/mads


Recommended Posts

I have written this program that writes hello and fills the screen with blank spaces again. I want to make a loop so that it first writes, then pauses for a while, writes the blank spaces, pauses for a while and then returns to the beginning. How do I do that?

org $3000
		pla
		lda #$28
		sta $9c40
		lda #$25
		sta $9c41
		lda #$2c
		sta $9c42
		sta $9c43
		lda #$2f
		sta $9c44
		lda #$0
		sta $9c40
		sta $9c41
		sta $9c42
		sta $9c43
		sta $9c44
		
		end
		

I am using mads, but I would prefer if the solution is as 'native' as possible. So that it is easy to implement with another assembler as well. Thanks in advance :)

Link to comment
Share on other sites

You could use the real time clock to idle for a while. This will pause for around a second:

	lda $14
	clc
	adc #200
PauseLoop
	cmp $14
	bne PauseLoop

Is your code called from BASIC via USR? If not, you don't need the PLA at the top (although I'm assuming this is a USR routine). You need RTS at the end to return to the caller, or an empty loop if you just want to stop after printing:

	jmp *

To return to the start, meanwhile, add a label at the top of the code and at the end add:

	jmp label_name
Edited by flashjazzcat
Link to comment
Share on other sites

Thanks! I took me a while to realize that I needed two loops but when I finaly understood it worked like charm :). What would be the best way to go about it if I wanted to have greater control over how long the computer pauses? In Basic I would use a for loop but in assembler I have no idea :)

Link to comment
Share on other sites

Since assembler runs magnitudes faster than BASIC, it's more difficult to create meaningful pauses without lots of nested loops. So you can fine tune that pause using the RTC, for example, by changing the value after the ADC instruction. The counter runs from 0-255, one tick per vertical blank, so that's 50 times a second for PAL, 60 for NTSC. So if you wanted a two second delay under NTSC, 255-120 = 135, so "ADC #135".

 

For much longer delays, you could think about using the next most significant byte of the 3-byte real time clock at $13, which counts over around once every five seconds.

Edited by flashjazzcat
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...