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 > Some sort of multithreading.
2008-04-08 22:51
gregg
Account closed

Registered: Apr 2005
Posts: 56
Some sort of multithreading.

About a week ago the topic multithreading came up on #c-64. So today I gave it a try. However, there's something wrong with my code and I can't really figure out what it is.

A short description: I have a fixed number of threads running and a CIA IRQ deals with context switching in a round-robin fashion. Every IRQ I save all current state data (SP, status register, PC, A, X, Y) in a structure and fetch the state data for the next thread.

In this example the first thread increments the screen background color (fast), while the second thread changes the border background color (slow). However the wait in the second thread runs too fast every other time, and I have no idea why. It's probably something wrong with the context switch stuff, maybe some of you could take a look at it?

Sources are for ACME.

!to "threading.prg",cbm
!cpu 6510
;!source "mylib.a"
!macro basic_header .a, .b, .c, .d {
        *= $0801
        !byte <.eol,>.eol,0,0,$9e
        !text .a, .b, .c, .d
.eol:   !byte 0,0,0
}

num_threads = 2
thread_num = $fd		; current thread number

;--------------------------------------------------------------------------
+basic_header "2", "0", "6", "1"

*= $080d

init:	sei
		; set up context switch IRQ
		lda #$35
		sta $01

		lda #<context_switch
		ldx #>context_switch
		sta $fffe
		stx $ffff
		
		lda #0
		sta thread_num

		cli
		jmp thread1

;--------------------------------------------------------------------------
context_switch:
		pha
		txa
		pha
		tya
		pha
		lda $dc0d

		; save current thread
		lda thread_num
		; *8
		asl
		asl
		asl
		tay
		; save A,X,Y
		pla
		sta thread_data+6,y
		pla
		sta thread_data+5,y
		pla
		sta thread_data+4,y
		; save PSW
		pla
		sta thread_data+1,y
		; save PC
		pla
		sta thread_data+2,y
		pla
		sta thread_data+3,y
		; save SP
		tsx
		txa
		sta thread_data,y

		; next thread, wraparound
		ldy thread_num
		iny
		cpy #num_threads
		bne +
		ldy #0
+		sty thread_num

		; *8
		tya
		asl
		asl
		asl
		tay

		; restore thread data
		; stack pointer first
		lda thread_data,y
		tax
		txs
		; push PC, PSW for RTI
		lda thread_data+3,y
		pha
		lda thread_data+2,y
		pha
		lda thread_data+1,y
		pha
		; push registers
		lda thread_data+6,y
		pha
		lda thread_data+5,y
		pha
		lda thread_data+4,y
		pha

		pla
		tay
		pla
		tax
		pla
		rti
	
;--------------------------------------------------------------------------
thread1:
		inc $d021
		ldy #$02
		jsr wait2
		jmp thread1


thread2:
		inc $d020
		ldy #$80
		jsr wait2
		jmp thread2
		
wait2:
-		ldx #0
		dex
		bne *-1
		dey
		bne -
		rts

;--------------------------------------------------------------------------
thread_data:
	!fill 8, 0
	!byte $ff-$40, $22, <thread2, >thread2, 0,0,0,0

 
... 211 posts hidden. Click here to view all posts....
 
2008-04-18 08:54
Frantic

Registered: Mar 2003
Posts: 1648
This THREAD is closed. Admit it!
2008-04-18 09:54
Zyron

Registered: Jan 2002
Posts: 2381
The thread is closed but the process continues...
2008-04-18 10:08
Martin Piper

Registered: Nov 2007
Posts: 722
ExitThread(-1);

? ;)
2008-04-18 11:50
Oswald

Registered: Apr 2002
Posts: 5094
Quote: Yes, Oswald is lacking the experience to be able to make these distinctions and instead resorts to trying to cite different parts of Wikipedia without understanding the much bigger picture.

Although I have to say a multi-threading system with multi-tasking processes is something to brag about as it's quite a lot of code to implement memory management, hardware resources management etc. ;)


Oh my dear. You lack the defined experience aswell, and you lack the brains to realize that aswell. Your only goal left is discredit me by saying your mantra "you are wrong, confused, etc" instead of having arguments that makes any sense. Groepaz its time to close the topic, as it is entering personal only stage.
2008-04-18 12:47
Martin Piper

Registered: Nov 2007
Posts: 722
You are wrong, I have the experience and the brains.
It is obvious that you do not because you are resorting to personal attacks instead of refuting the argument put before you. Your own posts discredit yourself and your "argument" because what you have been posting is demonstrably incorrect and the links you have been posting also show you are wrong. Lastly, the other posters in this thread are also telling you the same thing, that you are wrong. Yet you still continue to post the same rubbish.
2008-04-18 13:05
Oswald

Registered: Apr 2002
Posts: 5094
No I have the experience and brains and you dont, furthermore you are wrong because your own explanations proove you wrong. also you know you are wrong, but you dont admit that so you are trolling. now go back to kinder/trollgarten with this style of arguing dumbfuck.
2008-04-18 14:53
Martin Piper

Registered: Nov 2007
Posts: 722
Your repeated personal attacks demonstrate you're trolling and that your "argument" has failed.
2008-04-18 16:25
Oswald

Registered: Apr 2002
Posts: 5094
Your disability to refuse my arguments prooves that u r wrong. Oh forgot to add ur fave "point": it prooves aswell u r trolling.
2008-04-18 18:47
Slammer

Registered: Feb 2004
Posts: 416
It's clear that this discussion has lost all form of relevant content. Please stop it before you loose the respect you earned in other contexts.
2008-04-18 21:52
Martin Piper

Registered: Nov 2007
Posts: 722
Quote: Your disability to refuse my arguments prooves that u r wrong. Oh forgot to add ur fave "point": it prooves aswell u r trolling.

Your "arguments" are refuted because the links you provided do not support your case, if you actually read the links without selectively quoting tiny sections they also show exactly why you are wrong, you have not refuted my counter arguments, also you have not refuted the counter arguments of everybody else that says you're wrong. Since you are unable to refute any of this you are trolling and using personal attacks instead.
Previous - 1 | ... | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 - 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
Mike
TheRyk/MYD!
Alakran_64
Mibri/ATL^MSL^PRX
MWR/Visdom
DanPhillips
Rub_0201
LKP/CFN
megasoftargentina
Kakka/Extend, Damone..
Francois Prijt/Audia..
wil
Laddh
Guests online: 113
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 No Listen  (9.6)
2 Layers  (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 Censor Design  (9.3)
5 Triad  (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.049 sec.