Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user ATOO ! (Registered 2017-11-21) You are not logged in 
CSDb User Forums


Forums > C64 Coding > ACME macro for delaying X cycles
2017-10-24 15:02
Frantic

Registered: Mar 2003
Posts: 1319
ACME macro for delaying X cycles

Anybody got an macro handy for the ACME assembler for delaying X number of cycles? It is OK if it kills the A or X register.
 
... 14 posts hidden. Click here to view all posts....
 
2017-11-06 10:53
Cruzer

Registered: Dec 2001
Posts: 914
Just got a crazy idea for delaying 13 cycles in 1 byte:
pause:
	rti

delay13Cycles:
	brk
Requires that the IRQ/BRK vector is set to the pause label, and no IRQs occur at the same time, which I guess is unlikely anyway when cycle-exact timing is going on. However, after a little test it seems like the PC skips a byte after returning with rti, so in reality it takes two bytes:
pause:
	rti

delay13Cycles:
	brk
	.by 0
2017-11-06 11:07
Krill

Registered: Apr 2002
Posts: 902
Yes, BRK is a two-byte instruction. The operand byte is supposed to be an argument for the software interrupt you're triggering, pretty much similar to TRAP #<X> or INT <X> on other platforms.

It was intended for OS calls, i think, but i fail to come up with an example that actually uses the argument byte.
The 1581 ROM code only has a dummy parameter:
.8:959d  08          PHP
.8:959e  58          CLI
.8:959f  95 02       STA $02,X
.8:95a1  00          BRK
.8:95a2  EA          NOP
2017-11-08 00:01
Cruzer

Registered: Dec 2001
Posts: 914
Interesting, did not know that. Wonder why BRK isn't usually interpreted as having an argument by assemblers/disassemblers.
2017-11-08 06:27
Oswald

Registered: Apr 2002
Posts: 4126
so byte after brk is loaded into A ? or just thrown away ? isnt it just some kind of side effect from jsr ?
2017-11-08 08:36
ChristopherJam

Registered: Aug 2004
Posts: 682
Quoting Cruzer
However, after a little test it seems like the PC skips a byte after returning with rti, so in reality it takes two bytes


I guess you could make it a single byte 19 cycle delay by incrementing the return address in the interrupt handler, assuming you know the stack depth at the time of execution, and also avoid page boundary crossings in the 'caller'
2017-11-08 10:12
Krill

Registered: Apr 2002
Posts: 902
Quoting Cruzer
Wonder why BRK isn't usually interpreted as having an argument by assemblers/disassemblers.
Usually, yes. Some assemblers allow an optional argument. Default is without, as usually BRK is used to end a program, discarding any code or data after it.

Quoting Oswald
so byte after brk is loaded into A ? or just thrown away ? isnt it just some kind of side effect from jsr ?
The byte needs to be retrieved manually, reading it from stack after finding its position via TSX.
It may be possible that this is just a side-effect of saving gates or re-using some other logic (but probably not JSR with its two argument bytes).

But there was one real-world application which at least mildly suggests it was a conscious decision. The 6502 was designed as a micro-controller for industrial machines, not a general-purpose CPU for home computers. Back then, PROMs were used for custom or low-volume machines, which would be turned on and immediately manipulate physical objects in the real world. The PROMs came with all bits set, and were programmed by blowing fuses to flip bits to 0, but those bits could never be reset to 1.
Now, the BRK opcode is $00, and it could be used to patch code in PROMs. Upon encountering BRK (which was some other instruction formerly), the interrupt handler could then look up the argument byte (in addition or alternatively to the return address on stack) and decide which patch routine for that location (located in a patch area on the PROM) to execute, then resume operation.

Has anybody interviewed Mr Peddle about this? :)
2017-11-08 15:44
lft

Registered: Jul 2007
Posts: 314
But in that case, the byte following BRK would be some random byte from the original code. If multiple patches were used, there would be no guarantee that the extra bytes would be different from each other.

Meanwhile, the *address* of the extra byte is available on the stack, and you would have to retrieve it anyway in order to read the extra byte. Hence, it is easier to just use the address (which is unique) to distinguish between different patches.
2017-11-08 19:14
Oswald

Registered: Apr 2002
Posts: 4126
thanks for the clarification.

"The 6502 was designed as a micro-controller for industrial machines"

more accurately Chuck Peddle had ATM machines and POS terminals (till/cash register) in mind, and so on. Cheap CPU that can be built into everyday products.

this is in "on the edge".
2017-11-08 19:16
Frantic

Registered: Mar 2003
Posts: 1319
This is getting off topic
2017-11-08 20:39
Krill

Registered: Apr 2002
Posts: 902
Quoting lft
But in that case, the byte following BRK would be some random byte from the original code. If multiple patches were used, there would be no guarantee that the extra bytes would be different from each other.
Collection of 8 bits, to be precise, each of which you can null individually until having a unique byte. And if that fails, null the bits of consecutive bytes and read past null bytes in the BRK handler. But anyhow, yes, that argument byte's just a bonus, which might or might not come in handy depending on the use-case. And patches were probably relatively rare. :)
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
Dymo
TheRealWanderer
G-Force
Acidchild/Padua
Romppainen/ΤRIΛD
iAN CooG/HVSC
Scan/House Designs
TomoAlien
Guests online: 55
Top Demos
1 Uncensored  (9.7)
2 Edge of Disgrace  (9.7)
3 Coma Light 13  (9.6)
4 The Shores of Reflec..  (9.6)
5 Lunatico  (9.6)
6 Comaland 100%  (9.5)
7 Incoherent Nightmare  (9.5)
8 Wonderland XII  (9.5)
9 Comaland  (9.5)
10 Wonderland XIII  (9.5)
Top onefile Demos
1 Pandemoniac Part 2 o..  (9.6)
2 FMX Music Demo  (9.6)
3 Daah, Those Acid Pil..  (9.5)
4 Dawnfall V1.1  (9.5)
5 Synthesis  (9.5)
6 Dawnfall  (9.4)
7 Treu Love [reu]  (9.4)
8 Field Sort  (9.4)
9 Pro Memoria 4  (9.3)
10 KAOS 64  (9.3)
Top Groups
1 Oxyron  (9.4)
2 Booze Design  (9.4)
3 Censor Design  (9.3)
4 Crest  (9.3)
5 The Judges  (9.3)
Top Original Suppliers
1 Derbyshire Ram  (9.3)
2 hedning  (9.2)
3 Jazzcat  (9.1)
4 Irata  (9.0)
5 Fungus  (9.0)

Home - Disclaimer
Copyright © No Name 2001-2017
Page generated in: 1.696 sec.