EASy68K  
It is currently Sun May 31, 2020 12:42 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: stopwatch
PostPosted: Tue Dec 31, 2019 7:40 pm 
Offline

Joined: Tue Dec 31, 2019 7:05 pm
Posts: 1
can someone help me finish this code to make the programme pause if the letter r is pressed











ORG $1000
START: LEA MESSAGE,A1 ; load the message into A1
MOVE.B #14,D0
TRAP #15 ; display the message

MOVE #5,D0
TRAP #15 ; read a char from keyboard into D1.B

SUB.B #$73,D1
BNE end ; if the char is not S, it ends the program.

MOVE #8,D0 ; get time (in hundredths of sec) in D1
TRAP #15
MOVE.L D1,D2 ; copy the time to D2, D2 then is the start time

repeat MOVE #8,D0 ; the start of the loop
TRAP #15 ; get the time again, now the difference between D1 and D2 is the time that has passed.

SUB.L D2,D1 ; substract the start time, get the time that has passed.

DIVU #100,D1 ; LH is the reminder, RH is sec.

MOVE D1,D7 ; D7 is used here as a transfer to separate reminder and sec.
AND.L #$0000FFFF,D7 ; set the LH to zeros, only sec is left

MOVE.L D7,D3 ; move sec to D3

SWAP D1
AND.L #$0000FFFF,D1 ; swap D1 and clean the LH, only reminder left
MOVE.L D1,D4 ; put the reminder to D4

DIVU #60,D3 ; divide sec by 60, get minutes

MOVE.L D3,D7 ; D7 is used again as a transfer to separate min and sec(the reminder in this case)
AND.L #$0000FFFF,D7 ; set LH to zeros, only min is left
MOVE D7,D5 ; move min to D5

SWAP D3
AND.L #$0000FFFF,D3 ; swap D3, and set LH to zeros, only sec is left

MOVE.L D3,D6 ; move sec to D6

DIVU #10,D4 ; the reminder is divided by 10, get tenths
AND.L #$0000FFFF,D4 ; no need for the reminder in this case

* To sum up until this line, min is in D5, sec is in D6, tenth is in D4
* then start print

MOVE.L D5,D1 ; print min
MOVE #3,D0
TRAP #15

MOVE.B #$3A,D1 ; print colon
MOVE #6,D0
TRAP #15

MOVE.L D6,D1 ; print sec
MOVE #3,D0
TRAP #15

MOVE.B #$2E,D1 ; print full stop
MOVE #6,D0
TRAP #15

MOVE.L D4,D1 ; print tenths
MOVE #3,D0
TRAP #15

MOVE.W #$FF00,D1 ; clear screen
MOVE #11,D0
TRAP #15

SUB.B #$A,D5
BEQ end ; if the min, D5, is 10, then program ends


BRA repeat ; go back to the loop


end MOVE.B #7,D0
TRAP #15 ; halt simulator

* Variables and Strings

CR EQU $0D
LF EQU $0A
MESSAGE DC.B 'Press s to start the program',CR,LF,0


END START ; last line of source


Top
 Profile  
 
 Post subject: Re: stopwatch
PostPosted: Thu Feb 20, 2020 11:02 pm 
Offline

Joined: Thu Feb 20, 2020 8:02 pm
Posts: 11
You just need to have a "is running" variable/flag that you toggle with a key press, and at the beginning of your loop, you test that flag, and if not set you just skip everything and check keys again.

Look at the attached file and how the "run" variable is used there. It allows to start and stop the counter, it's very close to what you need, I suppose.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group