Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Timing Challenge
2017-04-28 12:12
TWW

Registered: Jul 2009
Posts: 545
Timing Challenge

Hello everyone. Figured I'd give you a small challenge before the weekend in terms of making a timing delay routine with the least amount of bytes and without destroying any registers for the following amounts of cycles:

26 cycles delay:
    pha         // 3
    pha         // 3
    pha         // 3
    nop         // 2
    bit $00     // 3
    pla         // 4
    pla         // 4
    pla         // 4 <- 26 cycles | 9 bytes


27 cycles delay:
    pha         // 3
    pha         // 3
    pha         // 3
    nop         // 2
    nop         // 2
    nop         // 2
    pla         // 4
    pla         // 4
    pla         // 4 <- 27 cycles | 9 bytes


31 cycles delay:
    pha             // 3
    lda #%00001000  // 2
    lsr             // 2 2 2 2
    bcc *-1         // 3 3 3 2
    bit $00         //       3
    pla             //       4 <- 31 cycles | 9 bytes


32 cycles delay:
    pha             // 3
    lda #%00001000  // 2
    lsr             // 2 2 2 2
    bcc *-1         // 3 3 3 2
    nop             //       2
    nop             //       2
    pla             //       4 <- 32 cycles | 9 bytes


31 cycles delay:
    pha             // 3
    lda #%00001000  // 2
    lsr             // 2 2 2 2
    bcc *-1         // 3 3 3 2
    nop             //       2
    nop             //       2
    nop             //       2
    pla             //       4 <- 34 cycles | 10 bytes


I have posted my solutions for reference and hope to see creative (hehe got it?) solutions ;-) Have a nice weekend^^
2017-04-28 12:21
JackAsser

Registered: Jun 2002
Posts: 2014
Obviosly SP, Flags and stack may be clobbered
2017-04-28 12:43
soci

Registered: Sep 2003
Posts: 480
.1000	20 03 20		jsr wait26

.2003	20 07 20	wait26	jsr +
.2006	ea			nop
.2007	60		+	rts
2017-04-28 13:09
soci

Registered: Sep 2003
Posts: 480
.1000	18		wait27	clc
.1001	b0			gcc +
.1002	38		-	sec
.1003	08		+	php
.1004	28			plp
.1005	90 fb			bcc -
.1007	ea			nop
2017-04-28 13:25
soci

Registered: Sep 2003
Posts: 480
.1000	20 07 28	jsr $2807		jsr wait31

.2807	20 08 28	jsr $2808	wait31  jsr wait31+1
.280a	60		rts			rts

Same idea can be used to shorten the 27 cycle delay above:
.1000	20 23 28	jsr $2823		jsr wait27

.2823	20 24 28	jsr $2824	wait27  jsr wait27+1
.2826	60		rts			rts

Or the 26 cycle one:
.1000	20 c8 28	jsr $28c8		jsr wait26

.28c8	20 c9 28	jsr $28c9	wait26  jsr wait26+1
.28cb	60		rts			rts

Etc.
2017-04-28 13:38
Bob

Registered: Nov 2002
Posts: 71
cool... but what is the point for throwing away cycles ?
I'll rather use them ;)
2017-04-28 18:48
TWW

Registered: Jul 2009
Posts: 545
Quoting JackAsser
Obviosly SP, Flags and stack may be clobbered


Sorry, should have been more specific, Flags can be messed with although the SP should be intact but the stack may be used as long as SP is restored upon exit.
2017-04-28 20:13
ChristopherJam

Registered: Aug 2004
Posts: 1409
Standard opcodes only, or are illegals allowed?

Can the routine require a page crossing at a given point within the sequence, or should we assume the sequence is all on the same page?
2017-04-30 21:07
TWW

Registered: Jul 2009
Posts: 545
IOPs and page alignment trickery allowed ;-)
2017-05-02 06:11
HCL

Registered: Feb 2003
Posts: 728
I would go for Soci:s method, or something with JMP to share the code. Like..:
Wait10
  jmp Wait7
Wait9
  jmp Wait6
Wait8
  jmp Wait5

Wait7
  jmp Wait4
Wait6
  jmp Wait3
Wait5
  jmp Wait2

Wait4
  nop
Wait2
  nop
  rts

Wait3
  bit 0
  rts
2017-05-02 06:44
Trash

Registered: Jan 2002
Posts: 122
I wouldnt consider size at all...
wait63 .byte $c9 ; cmp#
wait62 .byte $c9 ; cmp#
...
wait3 .byte $24 ; bit $
wait2 .byte $ea ; nop
rts ; 63 bytes for all delays between 69 and 8 cycles


...unless I had a really specific case
 
... 14 posts hidden. Click here to view all posts....
 
Previous - 1 | 2 | 3 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
t0m3000/hf^boom!^ibx
Andy/AEG
E$G/HF ⭐ 7
csabanw
sailor/Triad
acrouzet/G★P
Dano/Padua
The Human Co../Maste..
Flashback
Shake/Role
Hoild/Ultimate Newco..
Chesser/Blazon
Guests online: 137
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 No Listen  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Logo Graphicians
1 t0m3000  (10)
2 Sander  (9.8)
3 Mermaid  (9.5)
4 Facet  (9.4)
5 Shine  (9.4)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.039 sec.