-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTestTaskOS.asm
More file actions
167 lines (142 loc) · 3.53 KB
/
TestTaskOS.asm
File metadata and controls
167 lines (142 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//-------------------------------------------------------------
// Simple example of a tasking system
//-------------------------------------------------------------
// we only write CODE and DATA
.file [name="TestTaskOS.prg", segments="CODE,DATA"]
// NOTE: doesn't get written to the prg
.segment ZP [start=$02]
framecount: .byte 0
maxframes: .byte 0
.segment CODE [start=$0801]
.segment DATA [startAfter="CODE"]
.segment CODE
//-------------------------------------------------------------
// This creates a basic sys line that can start your program
//-------------------------------------------------------------
BasicUpstart2(Start)
// Our code
Start:
{
// just to disable the kernal messing around
sei
// Initialize the TaskOS
jsr TaskOS.Init
jsr SystemType
jsr Joystick.Reset
// for PAL setup
lda #$4
sta maxframes
sta framecount
lda SystemType.isNTSC
beq notNTSC
lda #$5
sta maxframes
notNTSC:
// add some sample tasks
TaskOS_RegisterFunction(Sample_Object.Init,0) // add Sample_Object and call it right away
TaskOS_RegisterFunction(Sample_Object.Init,240) // same but wait 240 frames first
// basic test
// wait for raster in middle of screen
vbl: lda $d012
cmp #$80
bne vbl
// handle difference between NTSC/PAL
// here we skip a frame on NTSC so the logic will always run 50 hz
dec framecount
bpl stepOS
lda maxframes
sta framecount
stepOS:
// if framecount == 5 then it's the frame we should skip on NTSC machines
// this value wont happen on PAL machines
lda framecount
cmp #$5
beq noTick
// step the TaskOS
inc $d020
jsr TaskOS.Step
dec $d020
noTick:
// display it
lda framecount
// screen coordinates
ldx #$04
ldy #$28
jsr Debug.PrintHex
jsr Joystick.Poll
// if we tap fire then ADD a task
ldx #Joystick.FIRE
jsr Joystick.Pressed
bne notPressed
TaskOS_RegisterFunction(Sample_Ticker,0) // add Sample Ticker
notPressed:
jmp vbl
}
//-------------------------------------------------------------
// just the bare example
// change the char on screen for this task
// x = task index
//-------------------------------------------------------------
Sample_Ticker:
inc $0400+400,x
lda $0400+400,x
cmp #$ff
bne noKill
// delete the task
lda #$00
sta TaskOS.UpdateMSB,x
noKill:
rts
//-------------------------------------------------------------
// more namespacey example
//-------------------------------------------------------------
Sample_Object:
{
.segment ZP
temp_var: .byte 0
// we can put our INIT function here
//
.segment CODE
// init gets called when the task is first called
Init:
{
// X is already this value
// though if you trash X
// you can get it back like this
ldx TaskOS.Step.CurrentTask
// we put an I on the screen
lda #'i'
sta $0400,x
// X is the current running task index
// so we use it to make a new value for delay
txa
asl
asl
asl
asl
// set our time and reset time to this value
sta TaskOS.ResetTime,x
sta TaskOS.Timer,x
// Change the function pointer
// to Update
TaskOS_SwitchFunction(Update)
rts
}
// we could skip the RTS above here and fall through to
// Init and Update in one shot, but we don't here for clarity
// the next "tick" after Init
Update:
{
// show we're update loop with U on screen
lda #'u'
sta $0400,x
// update the char underneath
inc $0428,x
rts
}
}
#import "C64.asm"
#import "Joystick.asm"
#import "TaskOS.asm"
#import "SystemType.asm"
#import "Debug.asm"