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


Forums > CSDb Entries > Release id #249931 : Two Tricks That Will Make You a Ridiculously Productive C64 Demo Coder
2025-02-08 01:45
Mixer

Registered: Apr 2008
Posts: 460
Release id #249931 : Two Tricks That Will Make You a Ridiculously Productive C64 Demo Coder

I thank you for the great talk Trident. The talk invited some reflection.

It is interesting that you come up with what is essentially scheduling and threads/processes from the simple need of making code easier to manage. This observation connects to something that in my experience happens in software development all the time.

The code that we produce has two classes of observers. One is the processor for which the readability or structure does not matter much. There may be some better performing sequences of instructions, but apart from that it has no preference. Then there is the human, the programmer who translates the human intent to processor code via a sequence of substitutions.

Lets say that there are two kind of problems, complex and difficult. Computing is complex. The foundations are very simple, just bits and binary logic, but to do something useful requires a lot of these components and the complexity emerges. Doing a back flip or climbing up a tree are difficult. They are difficult because of physical limitations of humans interacting with the world.

The complexity and difficulty meet in the human brain. Our brain has physical limitations and can only manage a couple of items in a few second interval. This means that in order to work with complex things, we must split everything into small chunks of just a few parts at a time. Thus it is a natural need for us to substitute groups of concepts with aggregate concepts and so on. This way the structure and organization of code and coding concepts are for humans by humans. This need also explains the thousands of design patterns and programming languages and frameworks that we've built for managing just our own concepts.

Our productivity increases when we find a new concept that can be substituted over an older one. In groups our productivity increases as we share these concepts. In projects and organizations we often choose to use particular tools or technology that is common for all programmers and so on, instead of what the processor might find most efficient.

One implication of all this is that when we plan stuff for people to do, we should take the brain into account and plan work for humans, not for "the processor" or a "process". Basically this means just splitting stuff into chunks and accepting that people can only do what they can see that they can do next. They've been researching why software is shit for decades and figured out ways to manage people and common information (agile, scrum, kanban, lean...) and so on, but that's another rant...

Well, anyway...
 
... 22 posts hidden. Click here to view all posts....
 
2025-02-08 19:33
wacek

Registered: Nov 2007
Posts: 526
As a non-programmer in real life, I really appreciate when seasoned ;) coders/programmers talk about that stuff. I learn from this a lot. I don't have an 'everyday for job programmer' experience, which I can draw from to code on the C64. This is very helpful.

Hats off to you, sirs ;)
2025-02-08 19:45
Mr SQL

Registered: Feb 2023
Posts: 158
Excellent presentation on raster driven coding with IRQ's to optimize placement and timing within a frame, 60x per second.

This is essentially following the Television threading model, i.e. programming the Television as a programmable device and not just the framebuffer.

Some viewers may have followed there are 60 frames per second and not 60 fields in the C64's video output.
2025-02-08 22:15
Digger

Registered: Mar 2005
Posts: 447
@Trident: Excellent talk!

It's funny because I was so close to anonymous IRQ handlers but I didn't see it.
I just needed this:
.macro @irqWait(rasterLine) {
    @irqSetAndExit(irq, rasterLine)
irq:
    @irqEnter()
}

Amazing it was hidden in a plain sight!

I badly need these NMI from IRQ macros. Is your code opensourced?
2025-02-08 23:14
Digger

Registered: Mar 2005
Posts: 447
Managed to trigger CIA1 timer A irq like this:

.macro @timerIrq(cycles) {
    lda #<cycles
    sta $dc04
    lda #>cycles
    sta $dc05
    lda #<irq
    sta $fffe
    lda #>irq
    sta $ffff

    lda #%00010001
    sta $dc0e
    lda #$81
    sta $dc0d
    lda $dc0d
    @irqExit()
irq:
    @irqEnter()
    lda #$7f
    sta $dc0d
    lda $dc0d
}


What's the 1st param in your macro "nmirasters_irq($10, $110)"?
Repeat $10 times every $100 cycles?
2025-02-09 11:49
Oswald

Registered: Apr 2002
Posts: 5118
I see another two tricks here.

1. reuse the same routine / effect a lot of times, and many of the effects are very cheap technically.

2. macro everything then one can just drop in full effects or fade routines with writing a line of code
2025-02-09 20:41
trident

Registered: May 2002
Posts: 101
@digger: the nmirasters code shows rasterbars via a timer interrupt and uses the nmi vector for the timer interrupt so that the irq vector can be used for stopping the timer when the right time has come. the code looks something like this:
    .macro nmirasters_irq(start, end) {
        irq_wait(start)
        irq_stable()

        lda #<nmi
        sta $fffa
        lda #>nmi
        sta $fffb

        lda #0
        sta $dd05
        lda #62
        sta $dd04

        lda #$81
        sta $dd0d
        lda $dd0d

        lda #$11
        sta $dd0e

        irq_wait(end)
        lda #0
        sta $dd0e
    }

the actual code is a little more intricate, as it needs to time the write to $dd0e correctly, but that's the gist of it.

it triggers an nmi interrupt every 63 cycles. the nmi code is placed in zero page. and there is an init function that copies the nmi code to zero page. that nmi code looks something like this:
    nmi:
    {
        sta atmp + 1
    lda: lda colors 
        sta $d020
        inc lda + 1
    atmp: lda #0
        jmp $dd0c
    }

that's 3 + 4 + 4 + 5 + 2 + 3 + 6 = 27 cycles, plus some 3 cycles for completing the current instruction + a few cycles for the interrupt itself, so around 50% of the total cpu time.

the $dd0c has been preloaded with the $40 rti instruction for a speedy rti + load from $dd0d, which is a quick way to return from and acknowledge the interrupt at the same time. it is a trick i believe Ninja was first to do.
2025-02-09 20:50
trident

Registered: May 2002
Posts: 101
@oswald: the way i see it, there are two types of code in c64 demo programming: utility code and virtuoso code. utility code is code we write to produce a specific outcome. virtuoso code is code we write to wow the audience. the virtuoso aspect is important, but so is the utility aspect.

code usually moves from being virtuoso code to being utility code. for example, the first fli image in So-Phisticated III was certainly virtuoso code. but now that same code is merely a way to display an image - utility code. likewise the first bitmap pictures with sideborder sprites were virtuoso code, but is now pretty much a standard feature.

a more personal example would be the text/bitmap stretcher code in The Demo Coder where is breaks a bunch of records and provides a few world's first, but a few demos later in O-Tech People III the same code is used for a fast "lemme stretch these petscii dudes real quick" - it has gone from virtuoso code to become a staple piece of utility code, useful for quickly achieving a specific outcome.

myself, i like to write code with the intent that it eventually will become utility code, even if it is being developed for its virtuoso aspects. it makes it easier, at least for me, to think that way when developing it.

btw this talk was very much about making utility coding easier. (my previous two fjälldata talks were much more focused on virtuoso aspects.)

oh, and i think the virtuoso aspect is key to demos in general, not just coding.
2025-02-09 22:53
Oswald

Registered: Apr 2002
Posts: 5118
@trident, ah so you even have this mindset, this also helps being productive.

I am old dinosaur, I have no macros I still write lda # sta $d018 code or type out a screen or memory clear and what not :P :)

those proto threads are clever stuff.
2025-02-09 23:33
Digger

Registered: Mar 2005
Posts: 447
@Oswald: Your output shows ;-) But seriously I find the utility stuff super boring and creativity killer. I am with Trident here - once solved it becomes utility and lets you move so much faster.
2025-02-10 12:19
Ninja

Registered: Jan 2002
Posts: 416
I maybe made the "RTI into $DD0C" trick popular but I definitely did not come up with it. Can't recall where I got it from, Marko Mäkelä and C=-Hacking would be my guess...
Previous - 1 | 2 | 3 | 4 - 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
csabanw
lotus_skylight
E$G/HF ⭐ 7
Mason/Unicess
BYB/Hokuto Force
Tom-Cat/Nostalgia
tlr
Hairdog/BOOM!^Dream
REBEL 1/HF
Poison/Singular Crew
wil/VCC^CTG
Guests online: 120
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.6)
4 Coma Light 13  (9.6)
5 Codeboys & Endians  (9.6)
6 Edge of Disgrace  (9.6)
7 Signal Carnival  (9.6)
8 Comaland 100%  (9.6)
9 What Is The Matrix 2  (9.6)
10 Uncensored  (9.6)
Top onefile Demos
1 At the Cinema  (9.8)
2 Nine  (9.8)
3 Layers  (9.6)
4 Cubic Dream  (9.6)
5 Party Elk 2  (9.6)
6 Datastiltje 2014 Win..  (9.5)
7 Copper Booze  (9.5)
8 Onscreen 5k  (9.5)
9 Libertongo  (9.5)
10 Charflasher  (9.5)
Top Groups
1 Artline Designs  (9.4)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Performers  (9.3)
5 Censor Design  (9.3)
Top Fullscreen Graphicians
1 Joe  (9.7)
2 Sulevi  (9.6)
3 The Sarge  (9.6)
4 Electric  (9.6)
5 Veto  (9.5)

Home - Disclaimer
Copyright © No Name 2001-2025
Page generated in: 0.12 sec.