ASM Newbie: Delays, waiting X seconds

Discuss all aspects of programming here. From 8-bit through to modern architectures.
User avatar
uniforix
Posts: 26
Joined: Sun Apr 21, 2013 9:57 pm
Contact:

ASM Newbie: Delays, waiting X seconds

Postby uniforix » Sun Dec 03, 2017 9:52 am

What's the best way to do say a 5 second delay? In BASIC I would reset TIME and wait for it to pass a threshold, in assembler I ended up creating a counter that counter down from 255 in another loop that counted down to 255 and called that numerous times, way overkill, sure there's likely a real easy way.

BTW I only started learning it yesterday haha :lol:

User avatar
jgharston
Posts: 2756
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield

Re: ASM Newbie: Delays, waiting X seconds

Postby jgharston » Sun Dec 03, 2017 5:47 pm

If you don't mind a keypress terminating the delay early:
LDX #centiseconddelay AND 255
LDY #centiseconddelay DIV 256
LDA #129:JSR OSBYTE

If it must delay the entire time, the simplest is to use *FX19 to count 1/50s VSyncs:
LDX #fiftithseconddelay AND 255
LDY #fiftithseconddelay DIV 256
.waitloop
TYA:PHA:TXA:PHA
LDA #19:JSR OSBYTE
PLA:TAX:PLA:TAY
DEX:BNE waitloop
DEY:BNE waitloop

This is how the BASIC V WAIT command works.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_


Return to “programming”

Who is online

Users browsing this forum: No registered users and 3 guests