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-16 11:24
Oswald

Registered: Apr 2002
Posts: 5031
Quote: You've not shown anything like that to be able to make such a claim.

I have quoted various sources upon what is multithreading. you have not. now rethink: who has the abilities to make such claims?
2008-04-16 11:31
Martin Piper

Registered: Nov 2007
Posts: 647
Quote: "In the context of this discussion the 6502 has two operating levels. One level is when it is executing an IRQ. The other not running an IRQ, we will call this the mainline."

read your definition again. how many times must I tell you the same thing? you cannot decide wether you are running irq or not, so u have no 2 op modes.


And again I will point you to post 85 which clarifies the situation and those terms as "IRQ mode and the mainline mode" and also "Also by setting or clearing the interrupt disable flag using SEI or CLI the code is actually causing he processor to switch between IRQ level to mainline operating level."
So like I have been saying you are wrong to keep on ignoring posts 80 and 85.
2008-04-16 11:31
Martin Piper

Registered: Nov 2007
Posts: 647
Quote: I have quoted various sources upon what is multithreading. you have not. now rethink: who has the abilities to make such claims?

You may have quoted the sources but your interpretation is flawed.
2008-04-16 11:38
Oswald

Registered: Apr 2002
Posts: 5031
Quote: And again I will point you to post 85 which clarifies the situation and those terms as "IRQ mode and the mainline mode" and also "Also by setting or clearing the interrupt disable flag using SEI or CLI the code is actually causing he processor to switch between IRQ level to mainline operating level."
So like I have been saying you are wrong to keep on ignoring posts 80 and 85.


so lets see your post #80

"In the context of this discussion the 6502 has two operating levels. One level is when it is executing an IRQ. The other not running an IRQ, we will call this the mainline.

Pre-emptive multi-threading can use interrupts to switch between thread contexts so that when the interrupt finishes the mainline resumes execution from a different point."

irq mode = running an irq
mainline mode = not running an irq

its crystal clear. your own stupid definition.
2008-04-16 11:39
Oswald

Registered: Apr 2002
Posts: 5031
Quote: You may have quoted the sources but your interpretation is flawed.

show me where.
2008-04-16 11:41
Martin Piper

Registered: Nov 2007
Posts: 647
Quote: so lets see your post #80

"In the context of this discussion the 6502 has two operating levels. One level is when it is executing an IRQ. The other not running an IRQ, we will call this the mainline.

Pre-emptive multi-threading can use interrupts to switch between thread contexts so that when the interrupt finishes the mainline resumes execution from a different point."

irq mode = running an irq
mainline mode = not running an irq

its crystal clear. your own stupid definition.


Again you are ignoring what was written in post 85.

The two operating levels are "IRQ mode and the mainline mode". This means "by setting or clearing the interrupt disable flag using SEI or CLI the code is actually causing he processor to switch between IRQ level to mainline operating level."

So you are wrong, again.
2008-04-16 11:44
Martin Piper

Registered: Nov 2007
Posts: 647
Quote: show me where.

For example when you keep on writing about privilege levels (post 96 is a good example), when it is irrelevant to this topic.
2008-04-16 11:50
Oswald

Registered: Apr 2002
Posts: 5031
Quote: Again you are ignoring what was written in post 85.

The two operating levels are "IRQ mode and the mainline mode". This means "by setting or clearing the interrupt disable flag using SEI or CLI the code is actually causing he processor to switch between IRQ level to mainline operating level."

So you are wrong, again.


then decide for god's sake, post #80 or #85 should be taken from you seriously? they are defining operating levels differently. one saying it is running or not running an irq, the other its the state of the I flag.

which of #80 or #85 post should be taken as your definition then? and which of the rest of your posts is bullshitting and which one is not ?
2008-04-16 11:53
Martin Piper

Registered: Nov 2007
Posts: 647
Quote: then decide for god's sake, post #80 or #85 should be taken from you seriously? they are defining operating levels differently. one saying it is running or not running an irq, the other its the state of the I flag.

which of #80 or #85 post should be taken as your definition then? and which of the rest of your posts is bullshitting and which one is not ?


It is very simple, you take both posts as part of my definition because post 85 follows on from post 80. Read post 80 first and then if you are still confused then you read post 85.
2008-04-16 11:56
Oswald

Registered: Apr 2002
Posts: 5031
your definition is flawed then. post #80 says the 2 modes are running or not running irq. post #85 says its about the I flag. in reality post #85 was just a reality skewer machine so you can save yourself being laughed at coz of the stupidity of pst #80.
Previous - 1 | ... | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | ... | 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
Twilight/Excess/Arcade
Nordischsound/Hokuto..
Matt
The Syndrom/TIA/Pret..
MightyAxle
t0m3000/HF^BOOM!^IBX
Knight Rider/TREX
Guests online: 91
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.7)
6 No Bounds  (9.6)
7 Aliens in Wonderland  (9.6)
8 Comaland 100%  (9.6)
9 Uncensored  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Cubic Dream  (9.6)
3 Party Elk 2  (9.6)
4 Copper Booze  (9.6)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Dawnfall V1.1  (9.5)
8 It's More Fun to Com..  (9.5)
9 Daah, Those Acid Pil..  (9.5)
10 Birth of a Flower  (9.5)
Top Groups
1 Nostalgia  (9.4)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 SHAPE  (9.3)
Top Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 hedning  (9.7)
4 Irata  (9.7)
5 Tim  (9.7)

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